Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 14 additions & 0 deletions Lib/test/test_concurrent_futures/test_process_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,20 @@ def test_force_shutdown_workers_stops_pool(self, function_name):
if not worker_process.is_alive():
break

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

@classmethod
def raiser(cls):
raise cls.MyException("foo")

def test_swallows_falsy_exceptions(self):
# fix gh-132063 issue
with self.assertRaisesRegex(self.MyException, "foo"):
with self.executor_type(max_workers=1) as executor:
executor.submit(self.raiser).result()


create_executor_tests(globals(), ProcessPoolExecutorTest,
executor_mixins=(ProcessPoolForkMixin,
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_concurrent_futures/test_thread_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ def log_n_wait(ident):
# ident='third' is cancelled because it remained in the collection of futures
self.assertListEqual(log, ["ident='first' started", "ident='first' stopped"])

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

@classmethod
def raiser(cls):
raise cls.MyException("foo")

def test_swallows_falsy_exceptions(self):
# fix gh-132063 issue
with self.assertRaisesRegex(self.MyException, "foo"):
with self.executor_type(max_workers=1) as executor:
executor.submit(self.raiser).result()

def setUpModule():
setup_module()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix tests of exception attribute in :method:`process_result_item`of :class:`_ExecutorManagerThread` and :method:`__get_result` of :class:`Future` in module :lib:`concurrent`.
Loading