@@ -2135,18 +2135,6 @@ def _busy_wait(self, timeout):
21352135 delay = min (delay * 2 , remaining , .05 )
21362136 time .sleep (delay )
21372137
2138- def _blocking_wait (self ):
2139- while self .returncode is None :
2140- with self ._waitpid_lock :
2141- if self .returncode is not None :
2142- break # Another thread waited.
2143- (pid , sts ) = self ._try_wait (0 )
2144- # Check the pid and loop as waitpid has been known to
2145- # return 0 even without WNOHANG in odd situations.
2146- # http://bugs.python.org/issue14396.
2147- if pid == self .pid :
2148- self ._handle_exitstatus (sts )
2149-
21502138 def _wait (self , timeout ):
21512139 """Internal implementation of wait() on POSIX."""
21522140 if self .returncode is not None :
@@ -2155,11 +2143,27 @@ def _wait(self, timeout):
21552143 if timeout is not None :
21562144 # Try fast wait first (pidfd on Linux, kqueue on BSD/macOS).
21572145 if self ._wait_pidfd (timeout ) or self ._wait_kqueue (timeout ):
2158- self ._blocking_wait ()
2146+ with self ._waitpid_lock :
2147+ if self .returncode is not None :
2148+ return self .returncode
2149+ pid , sts = self ._try_wait (os .WNOHANG )
2150+ if pid == self .pid :
2151+ self ._handle_exitstatus (sts )
2152+ return self .returncode
21592153 else :
21602154 self ._busy_wait (timeout )
21612155 else :
2162- self ._blocking_wait ()
2156+ while self .returncode is None :
2157+ with self ._waitpid_lock :
2158+ if self .returncode is not None :
2159+ break # Another thread waited.
2160+ (pid , sts ) = self ._try_wait (0 )
2161+ # Check the pid and loop as waitpid has been known to
2162+ # return 0 even without WNOHANG in odd situations.
2163+ # http://bugs.python.org/issue14396.
2164+ if pid == self .pid :
2165+ self ._handle_exitstatus (sts )
2166+
21632167 return self .returncode
21642168
21652169
0 commit comments