mirror of
https://github.com/python/cpython.git
synced 2025-10-15 11:22:18 +00:00
asyncio: be more lenient if we don't understand status returned by waitpid().
This should have no effect, it's a "shouldn't happe" case. Also tidied up some comments.
This commit is contained in:
parent
22c3176426
commit
8da15cc218
2 changed files with 14 additions and 14 deletions
|
@ -3,7 +3,6 @@
|
||||||
import collections
|
import collections
|
||||||
import errno
|
import errno
|
||||||
import fcntl
|
import fcntl
|
||||||
import functools
|
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
|
@ -167,22 +166,26 @@ 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
|
# Because of signal coalescing, we must keep calling waitpid() as
|
||||||
# long as we're able to reap a child
|
# long as we're able to reap a child.
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
pid, status = os.waitpid(-1, os.WNOHANG)
|
pid, status = os.waitpid(-1, os.WNOHANG)
|
||||||
except ChildProcessError:
|
except ChildProcessError:
|
||||||
break
|
break # No more child processes exist.
|
||||||
if pid == 0:
|
if pid == 0:
|
||||||
break
|
break # All remaining child processes are still alive.
|
||||||
elif os.WIFSIGNALED(status):
|
elif os.WIFSIGNALED(status):
|
||||||
|
# A child process died because of a signal.
|
||||||
returncode = -os.WTERMSIG(status)
|
returncode = -os.WTERMSIG(status)
|
||||||
elif os.WIFEXITED(status):
|
elif os.WIFEXITED(status):
|
||||||
|
# A child process exited (e.g. sys.exit()).
|
||||||
returncode = os.WEXITSTATUS(status)
|
returncode = os.WEXITSTATUS(status)
|
||||||
else:
|
else:
|
||||||
# shouldn't happen
|
# A child exited, but we don't understand its status.
|
||||||
continue
|
# This shouldn't happen, but if it does, let's just
|
||||||
|
# return that status; perhaps that helps debug it.
|
||||||
|
returncode = status
|
||||||
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)
|
||||||
|
@ -480,18 +483,15 @@ class _UnixSubprocessTransport(transports.SubprocessTransport):
|
||||||
loop = self._loop
|
loop = self._loop
|
||||||
if proc.stdin is not None:
|
if proc.stdin is not None:
|
||||||
transp, proto = yield from loop.connect_write_pipe(
|
transp, proto = yield from loop.connect_write_pipe(
|
||||||
functools.partial(
|
lambda: _UnixWriteSubprocessPipeProto(self, STDIN),
|
||||||
_UnixWriteSubprocessPipeProto, self, STDIN),
|
|
||||||
proc.stdin)
|
proc.stdin)
|
||||||
if proc.stdout is not None:
|
if proc.stdout is not None:
|
||||||
transp, proto = yield from loop.connect_read_pipe(
|
transp, proto = yield from loop.connect_read_pipe(
|
||||||
functools.partial(
|
lambda: _UnixReadSubprocessPipeProto(self, STDOUT),
|
||||||
_UnixReadSubprocessPipeProto, self, STDOUT),
|
|
||||||
proc.stdout)
|
proc.stdout)
|
||||||
if proc.stderr is not None:
|
if proc.stderr is not None:
|
||||||
transp, proto = yield from loop.connect_read_pipe(
|
transp, proto = yield from loop.connect_read_pipe(
|
||||||
functools.partial(
|
lambda: _UnixReadSubprocessPipeProto(self, STDERR),
|
||||||
_UnixReadSubprocessPipeProto, self, STDERR),
|
|
||||||
proc.stderr)
|
proc.stderr)
|
||||||
if not self._pipes:
|
if not self._pipes:
|
||||||
self._try_connected()
|
self._try_connected()
|
||||||
|
|
|
@ -266,7 +266,7 @@ class SelectorEventLoopTests(unittest.TestCase):
|
||||||
self.loop._subprocesses[7] = transp
|
self.loop._subprocesses[7] = transp
|
||||||
|
|
||||||
self.loop._sig_chld()
|
self.loop._sig_chld()
|
||||||
self.assertFalse(transp._process_exited.called)
|
self.assertTrue(transp._process_exited.called)
|
||||||
self.assertFalse(m_WEXITSTATUS.called)
|
self.assertFalse(m_WEXITSTATUS.called)
|
||||||
self.assertFalse(m_WTERMSIG.called)
|
self.assertFalse(m_WTERMSIG.called)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue