Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/concurrent/futures/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def done(self):
return self._state in [CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED]

def __get_result(self):
if self._exception:
if self._exception is not None:
try:
raise self._exception
finally:
Expand Down
2 changes: 1 addition & 1 deletion Lib/concurrent/futures/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def process_result_item(self, result_item):
work_item = self.pending_work_items.pop(result_item.work_id, None)
# work_item can be None if another process terminated (see above)
if work_item is not None:
if result_item.exception:
if result_item.exception is not None:
work_item.future.set_exception(result_item.exception)
else:
work_item.future.set_result(result_item.result)
Expand Down
27 changes: 27 additions & 0 deletions Lib/test/test_concurrent_futures/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ def my_method(self):
def make_dummy_object(_):
return MyObject()

# Used in test_swallows_falsey_exceptions
def raiser(exception, msg='std'):
raise exception(msg)


class FalseyBoolException(Exception):
def __bool__(self):
return False


class FalseyLenException(Exception):
def __len__(self):
return 0


class ExecutorTest:

Expand Down Expand Up @@ -205,3 +219,16 @@ def test_free_reference(self):
for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
if wr() is None:
break

def test_swallows_falsey_exceptions(self):
# see gh-132063: Prevent exceptions that evaluate as falsey
# from being ignored.
# Falsey exceptions return 0 when `__len__` method is called,
# False when `__bool__` method is called.

msg = 'lenlen'
with self.assertRaisesRegex(FalseyLenException, msg):
self.executor.submit(raiser, FalseyLenException, msg).result()
msg = 'boolbool'
with self.assertRaisesRegex(FalseyBoolException, msg):
self.executor.submit(raiser, FalseyBoolException, msg).result()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Prevent exceptions that evaluate as falsey (namely, when their ``__bool__`` method returns ``False`` or their ``__len__`` method returns 0)
from being ignored by :class:`concurrent.futures.ProcessPoolExecutor` and :class:`concurrent.futures.ThreadPoolExecutor`.
Loading