-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-132063: ProcessPoolExecutor swallows falsy Exceptions #132129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-132063: ProcessPoolExecutor swallows falsy Exceptions #132129
Conversation
@@ -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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the effort, but this is too many technical details for a blurb entry.
Fix tests of exception attribute in :method:`process_result_item`of :class:`_ExecutorManagerThread` and :method:`__get_result` of :class:`Future` in module :lib:`concurrent`. | |
Prevent exceptions that evaluate as falsey from being ignored | |
by :class:`concurrent.futures.ProcessPoolExecutor`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not limited to __bool__
, it can be anything that is falsey, including a class which implements __len__
as well (https://docs.python.org/3/reference/datamodel.html#object.__bool__)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest:
Prevent exceptions, including group exceptions, that evaluate as falsey (With bool
and len
dunder methods returns) from being ignored
by :class:concurrent.futures.ProcessPoolExecutor
and :class:concurrent.futures.ThreadPoolExecutor
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like to mention bool and len again so how about linking falsey to object.__bool__
?
:meth:`falsey <object.__bool__>`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth adding a "falsey" term to the glossary, but that should be done elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never sent my review.
@@ -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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not limited to __bool__
, it can be anything that is falsey, including a class which implements __len__
as well (https://docs.python.org/3/reference/datamodel.html#object.__bool__)
After more tests, I found that Line 1123 in 255eb37
Line 1144 in 255eb37
And falsey BaseExceptionGroup exception is ignored too.Line 1159 in 255eb37
Should we open a new issue with these bugs or integrate them to this PR ? EDIT: please ignore this comment |
Misc/NEWS.d/next/Library/2025-04-05-15-05-09.gh-issue-132063.KHnslU.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits and LGTM.
|
||
msg = 'boolbool' | ||
with self.assertRaisesRegex(FalseyBoolException, msg): | ||
self.executor.submit(raiser, FalseyBoolException, msg).result() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for a possible follow-up but this kind of call makes me wonder whether the base class shouldn't have some def submit_and_fetch(self)
method that does this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this method return directy the result ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a follow-up with the TracebackException
class which swallows __cause__
and __context__
content of falsey exceptions.
I will post a new issue about this.
…alsey exceptions (pythonGH-132129) (cherry picked from commit 933c665) Co-authored-by: Duprat <yduprat@gmail.com>
GH-132275 is a backport of this pull request to the 3.13 branch. |
…alsey exceptions (python#132129)
ProcessPoolExecutor and ThreadPoolExecutor swallows falsy exception.
Fix tests about exception variable in 2 files of /Lib/concurrent/futures
Changes 2 tests as below:
Replace
if exception:
withif exception is not None: