Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
gh-83069: Use efficient event-drivensubprocess.Popen.wait() on Linux / macOS / BSD#144047
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
vstinner left a comment
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
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.
Lib/test/test_subprocess.py Outdated
| assertm1.called | ||
| assertm2.called |
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.
| assertm1.called | |
| assertm2.called | |
| self.assertTrue(m1.called) | |
| self.assertTrue(m2.called) |
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.
You don't want to replaceassert here?
Uh oh!
There was an error while loading.Please reload this page.
Lib/test/test_subprocess.py Outdated
| withself.assertRaises(subprocess.TimeoutExpired): | ||
| p.wait(timeout=0.0001) | ||
| self.assertEqual(p.wait(timeout=support.LONG_TIMEOUT),0) | ||
| assertnotm.called |
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.
| assertnotm.called | |
| self.assertFalse(m.called) |
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.
You don't want to replaceassert here?
Uh oh!
There was an error while loading.Please reload this page.
giampaolo commentedJan 21, 2026
Thanks for the review@vstinner. I addressed your comments. |
Uh oh!
There was an error while loading.Please reload this page.
vstinner left a comment
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!
Lib/test/test_subprocess.py Outdated
| assertm1.called | ||
| assertm2.called |
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.
You don't want to replaceassert here?
Lib/test/test_subprocess.py Outdated
| withself.assertRaises(subprocess.TimeoutExpired): | ||
| p.wait(timeout=0.0001) | ||
| self.assertEqual(p.wait(timeout=support.LONG_TIMEOUT),0) | ||
| assertnotm.called |
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.
You don't want to replaceassert here?
giampaolo commentedJan 22, 2026
Whops! I fixed the remaining bare |
vstinner commentedJan 22, 2026
@gpshead: Do you want to double check the change? |
giampaolo commentedJan 24, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
In the hope of adding BSD / macOS support for |
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 atimeout 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 (seegiampaolo/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/