Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2019-11-21.21:43:43.189>labels= ['type-feature', 'library', '3.9']
title='Popen should use pidfd_open to implement a non-busy wait'updated_at=<Date2019-11-21.22:20:50.812>user='https://github.com/SpecLad'
Popen.wait(timeout) is currently implemented on Unix-like systems using a busy wait, since the waitpid system call doesn't have a timeout argument.
On Linux, it's now possible to do better than that. You can create a PID file descriptor using pidfd_create and poll that descriptor with the specified timeout. Popen.wait should make use of that.
changed the title [-]Popen should use pidfd_create to implement a non-busy wait[/-][+]Popen should use pidfd_open to implement a non-busy wait[/+]on Nov 21, 2019
Hi. Since I recently implemented this in psutil (giampaolo/psutil#2706), I decided to give this a try and port this change to the subprocess module. I created a PR which uses pidfd_open() on Linux and also adds support for macOS and BSD by using kqueue(): #144047.
Activity
SpecLad commented on Nov 21, 2019
Popen.wait(timeout) is currently implemented on Unix-like systems using a busy wait, since the waitpid system call doesn't have a timeout argument.
On Linux, it's now possible to do better than that. You can create a PID file descriptor using pidfd_create and poll that descriptor with the specified timeout. Popen.wait should make use of that.
vstinner commented on Nov 21, 2019
os.pidfd_open() was added to Python 3.9. Do you mean pidfd_open()?
SpecLad commented on Nov 21, 2019
Right, of course. I keep confusing it with timerfd_create.
giampaolo commented on Jan 19, 2026
Hi. Since I recently implemented this in psutil (giampaolo/psutil#2706), I decided to give this a try and port this change to the subprocess module. I created a PR which uses pidfd_open() on Linux and also adds support for macOS and BSD by using kqueue(): #144047.
gh-83069: Use efficient event-driven `subprocess.Popen.wait()` on Lin…
vstinner commented on Jan 28, 2026
The feature is now implemented, I close the issue.
pythongh-83069: Use efficient event-driven `subprocess.Popen.wait()` …
gh-154836: Fix Popen.wait() with very large timeouts on the pidfd/kqu…
[3.15] gh-154836: Fix Popen.wait() with very large timeouts on the pi…
pythongh-154836: Fix Popen.wait() with very large timeouts on the pid…