Skip to content

gh-96863: Fix subprocess.Popen.wait to raise ProcessLookupError for external waits #137804

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

Closed
wants to merge 6 commits into from

Conversation

Writtic
Copy link

@Writtic Writtic commented Aug 15, 2025

@python-cla-bot
Copy link

python-cla-bot bot commented Aug 15, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

proc.wait()
try:
proc.wait()
except ProcessLookupError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I’ll use assertRaises here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems it’s not always raised, so I’ll revert to using a try–except block on cb8d874.

sts = 0
return (pid, sts)

raise ProcessLookupError(f'Process {self.pid} is already waited on externally')
Copy link
Member

@corona10 corona10 Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gpshead I think that we should specify status code rather than raise exception because it will change current behavior. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callers do not expect wait() to raise an exception when the process has died by default because our behavior has been not to raise. Often callers don't even care about the exit code. As seen in the tests that had to be updated due to this proposed change. I'm sure people have written code that calls wait multiple times as well, expecting later calls to be no-ops. We don't want to break that.

I'll reply further on the issue. I do not think we want this feature.

@gpshead
Copy link
Member

gpshead commented Aug 17, 2025

BTW, thanks for the contribution! not all PRs make sense, getting eyeballs on issues that perhaps haven't had sufficient discussion and discussing what is actually needed is the larger benefit in such situations. :) (ie: don't feel bad that i'm closing your PR, it was helpful regardless - see the discussion on the issue, i think other PR opportunities exist for this one)

@gpshead gpshead closed this Aug 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants