GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@fedonman fedonman commented Jul 18, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

  • Issue: subprocess: Popen._internal_poll silently swallows unexpected OSError from waitpid() #153962

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@fedonman
pythongh-153962: Re-raise unexpected OSError in subprocess Popen._int…
ba1f9aa
…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.
@fedonman
fedonman requested a review from gpshead as a code owner July 18, 2026 13:36
@bedevere-app bedevere-app Bot mentioned this pull request Jul 18, 2026
subprocess: Popen._internal_poll silently swallows unexpected OSError from waitpid() #153962
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Jul 18, 2026
@fedonman
Merge branch 'main' into fix-pythongh-153962-internal-poll-oserror
268c11a
@fedonman

fedonman commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

@zware part of EuroPython sprint.

zware reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zware zware added the sprint label Jul 19, 2026
@github-project-automation github-project-automation Bot added this to Sprint Jul 19, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Sprint Jul 19, 2026
fedonman added 2 commits July 21, 2026 15:32
@fedonman
Merge branch 'main' into fix-pythongh-153962-internal-poll-oserror
b37dd6e
@fedonman
Merge branch 'main' into fix-pythongh-153962-internal-poll-oserror
9e11f26
@zware

zware commented Jul 27, 2026

Copy link
Copy Markdown
Member

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
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fedonman

fedonman commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Noted!

zware reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka reviewed Aug 16, 2026
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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.

See also @vstinner's objection on the issue.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/subprocess.py
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

@serhiy-storchaka serhiy-storchaka Aug 16, 2026

Copy link
Copy Markdown
Member

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.

All reactions
@vstinner

vstinner commented Aug 31, 2026

Copy link
Copy Markdown
Member

I suggest closing the PR and its issue.

I'm not sure that it's worth it to fix a theoretical issue.

The PR issue says:

Found while going through devdanzin's audit of the standard library, item 8: https://gist.github.com/devdanzin/3198710e3c0128fda5e0a7b4e0768e5f

So only error fault injection can trigger the issue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fedonman

fedonman commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing after @vstinner suggestion.

vstinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fedonman fedonman closed this Sep 2, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in Sprint Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@gpshead 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

Labels

awaiting review sprint

Projects

Sprint
Archived in project

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

subprocess: Popen._internal_poll silently swallows unexpected OSError from waitpid()

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@fedonman @zware @vstinner @serhiy-storchaka
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.