GeezerVison is showing github.com — gh-153962: Re-raise unexpected `OSError` in subprocess `Popen._internal_poll` by fedonman · Pull Request #153964 · python/cpython
Conversation
fedonman
commented
Jul 18, 2026
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
On POSIX, Popen.poll() caught every OSError from os.waitpid() but only did something useful with two of them: ECHILD, and the case where the call comes from __del__. Any other error, like EINVAL, was caught and dropped, which left returncode as None and made poll() look like the child was still running.
This adds an else: raise so those unexpected errors reach the caller instead of vanishing.
The new raise only runs when the call isn't from __del__ (that case is handled first, since it passes a deadstate value), so __del__ still never raises. The ECHILD behavior is unchanged.
I added a test that patches subprocess._del_safe.waitpid to raise EINVAL and checks that poll() re-raises it. It fails without the change and passes with it, and the rest of test_subprocess still passes. The patch goes through subprocess._del_safe because that's the copy of os.waitpid this code actually calls.
Found as item 8 in devdanzin's standard library audit: https://gist.github.com/devdanzin/3198710e3c0128fda5e0a7b4e0768e5f
Fixes #153962.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…ernal_poll
On POSIX, Popen._internal_poll() caught every OSError from os.waitpid()
and, unless it was ECHILD or the call came from __del__ (a non-None
_deadstate), silently discarded it, leaving returncode as None and
masking a real failure.
Add an else branch that re-raises such unexpected errors. The re-raise is
only reachable when _deadstate is None; __del__ and _cleanup() always
pass a non-None _deadstate, so __del__ still never raises. ECHILD
handling is unchanged.
|
@zware part of EuroPython sprint.
|
zware reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Note: Please don't do these periodic Update branch merges if they're not fixing conflicts. It's impossible to stay perfectly up to date, and it's a drain on CI resources to re-test the same code repeatedly with no other action. If necessary, a maintainer can do a branch update just before merge for a final check.
|
fedonman reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
zware reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+2195
to
+2200
|
|
# An unexpected error (e.g. EINVAL) must not be
|
|
|
# silently swallowed, leaving returncode as None:
|
|
|
# surface it to the caller. This branch is never
|
|
|
# reached from __del__, which always passes a
|
|
|
# non-None _deadstate.
|
|
|
raise
|
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 harms readability if the comment is 5 times large than the actual code, especially if the code is presumably unreachable. I suggest either to leave a minimal one-line comment or to remove it.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
vstinner reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
gpshead
Awaiting requested review from gpshead
gpshead is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|