Issue #19310: asyncio: fix child processes reaping logic.

This commit is contained in:
Charles-François Natali 2013-10-20 23:23:44 +02:00
parent e5a3154c63
commit 5121debebf
1 changed files with 19 additions and 17 deletions

View File

@ -167,20 +167,22 @@ class SelectorEventLoop(selector_events.BaseSelectorEventLoop):
def _sig_chld(self):
try:
# because of signal coalescing, we must keep calling waitpid() as
# long as we're able to reap a child
while True:
try:
pid, status = os.waitpid(-1, os.WNOHANG)
except ChildProcessError:
return
break
if pid == 0:
self.call_soon(self._sig_chld)
return
break
elif os.WIFSIGNALED(status):
returncode = -os.WTERMSIG(status)
elif os.WIFEXITED(status):
returncode = os.WEXITSTATUS(status)
else:
self.call_soon(self._sig_chld)
return
# shouldn't happen
continue
transp = self._subprocesses.get(pid)
if transp is not None:
transp._process_exited(returncode)