Skip to content

Commit 9efa479

Browse files
committed
Initial commit
1 parent df59226 commit 9efa479

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

Lib/concurrent/futures/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def done(self):
390390
return self._state in [CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED]
391391

392392
def __get_result(self):
393-
if self._exception:
393+
if self._exception is not None:
394394
try:
395395
raise self._exception
396396
finally:

Lib/concurrent/futures/process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def process_result_item(self, result_item):
440440
work_item = self.pending_work_items.pop(result_item.work_id, None)
441441
# work_item can be None if another process terminated (see above)
442442
if work_item is not None:
443-
if result_item.exception:
443+
if result_item.exception is not None:
444444
work_item.future.set_exception(result_item.exception)
445445
else:
446446
work_item.future.set_result(result_item.result)

Lib/test/test_concurrent_futures/test_process_pool.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,20 @@ def test_force_shutdown_workers_stops_pool(self, function_name):
337337
if not worker_process.is_alive():
338338
break
339339

340+
class MyException(Exception):
341+
def __bool__(self):
342+
return False
343+
344+
@classmethod
345+
def raiser(cls):
346+
raise cls.MyException("foo")
347+
348+
def test_swallows_falsy_exceptions(self):
349+
# fix gh-132063 issue
350+
with self.assertRaisesRegex(self.MyException, "foo"):
351+
with self.executor_type(max_workers=1) as executor:
352+
executor.submit(self.raiser).result()
353+
340354

341355
create_executor_tests(globals(), ProcessPoolExecutorTest,
342356
executor_mixins=(ProcessPoolForkMixin,

Lib/test/test_concurrent_futures/test_thread_pool.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ def log_n_wait(ident):
112112
# ident='third' is cancelled because it remained in the collection of futures
113113
self.assertListEqual(log, ["ident='first' started", "ident='first' stopped"])
114114

115+
class MyException(Exception):
116+
def __bool__(self):
117+
return False
118+
119+
@classmethod
120+
def raiser(cls):
121+
raise cls.MyException("foo")
122+
123+
def test_swallows_falsy_exceptions(self):
124+
# fix gh-132063 issue
125+
with self.assertRaisesRegex(self.MyException, "foo"):
126+
with self.executor_type(max_workers=1) as executor:
127+
executor.submit(self.raiser).result()
115128

116129
def setUpModule():
117130
setup_module()

0 commit comments

Comments
 (0)