mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-132063: ensure that ProcessPoolExecutor
does not swallow falsey exceptions (#132129)
This commit is contained in:
parent
c5e856a5dc
commit
933c6653cb
4 changed files with 32 additions and 2 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue