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
gh-83069: Use efficient event-driven subprocess.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.
# Check the pid and loop as waitpid has been known to
# return 0 even without WNOHANG in odd situations.
# http://bugs.python.org/issue14396.
if pid == self.pid:
self._handle_exitstatus(sts)
def _wait(self, timeout):
"""Internal implementation of wait() on POSIX."""
if self.returncode is not None:
Expand All
@@ -2155,11 +2143,27 @@ def _wait(self, timeout):
if timeout is not None:
# Try fast wait first (pidfd on Linux, kqueue on BSD/macOS).
if self._wait_pidfd(timeout) or self._wait_kqueue(timeout):
self._blocking_wait()
with self._waitpid_lock:
if self.returncode is not None:
return self.returncode
pid, sts = self._try_wait(os.WNOHANG)
if pid == self.pid:
self._handle_exitstatus(sts)
return self.returncode
else:
self._busy_wait(timeout)
else:
self._blocking_wait()
while self.returncode is None:
with self._waitpid_lock:
if self.returncode is not None:
break # Another thread waited.
(pid, sts) = self._try_wait(0)
# Check the pid and loop as waitpid has been known to
# return 0 even without WNOHANG in odd situations.
# http://bugs.python.org/issue14396.
if pid == self.pid:
self._handle_exitstatus(sts)
return self.returncode
Expand Down
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.