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

View file

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