Skip to content

Conversation

@giampaolo
Copy link
Contributor

@giampaolo giampaolo commented Jan 19, 2026

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.


📚 Documentation preview 📚: https://cpython-previews--144047.org.readthedocs.build/

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.

1 participant