gh-83069: Use efficient event-driven subprocess.Popen.wait() on Linux / macOS / BSD#144047
Merged
vstinner merged 68 commits intopython:mainfrom Jan 28, 2026
Merged
gh-83069: Use efficient event-driven subprocess.Popen.wait() on Linux / macOS / BSD#144047vstinner merged 68 commits intopython:mainfrom
subprocess.Popen.wait() on Linux / macOS / BSD#144047vstinner merged 68 commits intopython:mainfrom
Conversation
Contributor
Author
|
Thanks for the review @vstinner. I addressed your comments. |
vstinner
reviewed
Jan 21, 2026
vstinner
approved these changes
Jan 22, 2026
Member
vstinner
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the updates!
Contributor
Author
|
Whops! I fixed the remaining bare |
Member
|
@gpshead: Do you want to double check the change? |
Contributor
Author
|
In the hope of adding BSD / macOS support for |
Member
|
Merged, thank you for this nice optimization! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This patch replaces the busy-loop mechanism used by
subprocess.Popen.wait()on Linux, BSD, and macOS when a timeout is specified:os.pidfd_open()+select.poll()select.kqueue()+KQ_FILTER_PROC+KQ_NOTE_EXITThe kernel wakes us up exactly when the PID terminates or the timeout expires. If the fast-wait mechanisms is not available or fails (e.g. "too many open files"), the function falls back to the traditional busy loop. A similar approach was recently implemented in psutil (see giampaolo/psutil#2706). While working on that change, I noticed that the subprocess module used essentially the same busy-loop strategy, which motivated this proposal.
📚 Documentation preview 📚: https://cpython-previews--144047.org.readthedocs.build/