gh-132063: ensure that ProcessPoolExecutor does not swallow falsey exceptions (#132129)

This commit is contained in:
Duprat 2025-04-08 17:11:13 +02:00 committed by GitHub
parent c5e856a5dc
commit 933c6653cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 2 deletions

View file

@ -24,6 +24,21 @@ 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:
# Executor.shutdown() and context manager usage is tested by
@ -205,3 +220,16 @@ class ExecutorTest:
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.
# Recall: `x` is falsey if `len(x)` returns 0 or `bool(x)` returns False.
msg = 'boolbool'
with self.assertRaisesRegex(FalseyBoolException, msg):
self.executor.submit(raiser, FalseyBoolException, msg).result()
msg = 'lenlen'
with self.assertRaisesRegex(FalseyLenException, msg):
self.executor.submit(raiser, FalseyLenException, msg).result()