Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit933c665

Browse files
authored
gh-132063: ensure thatProcessPoolExecutor does not swallow falsey exceptions (#132129)
1 parentc5e856a commit933c665

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-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
returnself._statein [CANCELLED,CANCELLED_AND_NOTIFIED,FINISHED]
391391

392392
def__get_result(self):
393-
ifself._exception:
393+
ifself._exceptionisnotNone:
394394
try:
395395
raiseself._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
ifwork_itemisnotNone:
443-
ifresult_item.exception:
443+
ifresult_item.exceptionisnotNone:
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/executor.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ def make_dummy_object(_):
2424
returnMyObject()
2525

2626

27+
# Used in test_swallows_falsey_exceptions
28+
defraiser(exception,msg='std'):
29+
raiseexception(msg)
30+
31+
32+
classFalseyBoolException(Exception):
33+
def__bool__(self):
34+
returnFalse
35+
36+
37+
classFalseyLenException(Exception):
38+
def__len__(self):
39+
return0
40+
41+
2742
classExecutorTest:
2843

2944
# Executor.shutdown() and context manager usage is tested by
@@ -205,3 +220,16 @@ def test_free_reference(self):
205220
for_insupport.sleeping_retry(support.SHORT_TIMEOUT):
206221
ifwr()isNone:
207222
break
223+
224+
deftest_swallows_falsey_exceptions(self):
225+
# see gh-132063: Prevent exceptions that evaluate as falsey
226+
# from being ignored.
227+
# Recall: `x` is falsey if `len(x)` returns 0 or `bool(x)` returns False.
228+
229+
msg='boolbool'
230+
withself.assertRaisesRegex(FalseyBoolException,msg):
231+
self.executor.submit(raiser,FalseyBoolException,msg).result()
232+
233+
msg='lenlen'
234+
withself.assertRaisesRegex(FalseyLenException,msg):
235+
self.executor.submit(raiser,FalseyLenException,msg).result()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Prevent exceptions that evaluate as falsey (namely, when their ``__bool__`` method returns ``False`` or their ``__len__`` method returns 0)
2+
from being ignored by:class:`concurrent.futures.ProcessPoolExecutor` and:class:`concurrent.futures.ThreadPoolExecutor`.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp