We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 645ef6c commit 6ee771bCopy full SHA for 6ee771b
1 file changed
Lib/subprocess.py
@@ -2157,7 +2157,13 @@ def _wait(self, timeout):
2157
if timeout < 0:
2158
raise TimeoutExpired(self.args, timeout)
2159
if self._wait_pidfd(timeout) or self._wait_kqueue(timeout):
2160
- self._blocking_wait()
+ # At this point os.waitpid(pid, 0) should return
2161
+ # immediately, but in rare races another thread or
2162
+ # signal handler may have already reaped the PID.
2163
+ # Using _busy_wait(0) (WNOHANG) ensures we attempt
2164
+ # a non-blocking reap safely without blocking
2165
+ # indefinitely.
2166
+ self._busy_wait(0)
2167
else:
2168
self._busy_wait(timeout)
2169
0 commit comments