GeezerVison is showing github.com — gh-83069: Use efficient event-driven `subprocess.Popen.wait()` on Linux / macOS / BSD by giampaolo · Pull Request #144047 · python/cpython
Conversation
giampaolo
commented
Jan 19, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
This patch replaces the busy-loop mechanism used by subprocess.Popen.wait() on Linux, BSD, and macOS when a timeout is specified:
- Linux >= 5.3: uses
os.pidfd_open() + select.poll()
- macOS, BSD: uses
select.kqueue() + KQ_FILTER_PROC + KQ_NOTE_EXIT
The 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.
EDIT: I wrote a blog post about this: https://gmpy.dev/blog/2026/event-driven-process-waiting
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
soltanoff, 5j9, saisua, and kaizen-cmd reacted with heart emoji
mbeijen, takluyver, and kaizen-cmd reacted with rocket emoji
All reactions
-
❤️
4 reactions
-
🚀
3 reactions
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.
Nice change! I like it. Here is a first review.
cc @gpshead
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for the review @vstinner. I addressed your comments.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
LGTM. Thanks for the updates!
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Whops! I fixed the remaining bare assert statements.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@gpshead: Do you want to double check the change?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
giampaolo
commented
Jan 24, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
In the hope of adding BSD / macOS support for asyncio in the future, I have opened #144211.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Merged, thank you for this nice optimization!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jul 28, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|