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

parent e5a3154c
...@@ -167,20 +167,22 @@ class SelectorEventLoop(selector_events.BaseSelectorEventLoop): ...@@ -167,20 +167,22 @@ class SelectorEventLoop(selector_events.BaseSelectorEventLoop):
def _sig_chld(self): def _sig_chld(self):
try: try:
# because of signal coalescing, we must keep calling waitpid() as
# long as we're able to reap a child
while True:
try: try:
pid, status = os.waitpid(-1, os.WNOHANG) pid, status = os.waitpid(-1, os.WNOHANG)
except ChildProcessError: except ChildProcessError:
return break
if pid == 0: if pid == 0:
self.call_soon(self._sig_chld) break
return
elif os.WIFSIGNALED(status): elif os.WIFSIGNALED(status):
returncode = -os.WTERMSIG(status) returncode = -os.WTERMSIG(status)
elif os.WIFEXITED(status): elif os.WIFEXITED(status):
returncode = os.WEXITSTATUS(status) returncode = os.WEXITSTATUS(status)
else: else:
self.call_soon(self._sig_chld) # shouldn't happen
return continue
transp = self._subprocesses.get(pid) transp = self._subprocesses.get(pid)
if transp is not None: if transp is not None:
transp._process_exited(returncode) transp._process_exited(returncode)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment