summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@dropbox.com>2013-10-21 22:00:44 (GMT)
committerGuido van Rossum <guido@dropbox.com>2013-10-21 22:00:44 (GMT)
commit8da15cc2189a97500e83cd50ab761920365fcdf1 (patch)
tree9e06dd22ba3176703c074833a1974e4c5fb10b99
parent22c31764262b02338265a059c738b8d24fd9a0e4 (diff)
downloadcpython-8da15cc2189a97500e83cd50ab761920365fcdf1.zip
cpython-8da15cc2189a97500e83cd50ab761920365fcdf1.tar.gz
cpython-8da15cc2189a97500e83cd50ab761920365fcdf1.tar.bz2
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.
-rw-r--r--Lib/asyncio/unix_events.py26
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py2
2 files changed, 14 insertions, 14 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index b4e2699..8c0e09a 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -3,7 +3,6 @@
import collections
import errno
import fcntl
-import functools
import os
import signal
import socket
@@ -167,22 +166,26 @@ 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
+ # 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:
- break
+ break # No more child processes exist.
if pid == 0:
- break
+ break # All remaining child processes are still alive.
elif os.WIFSIGNALED(status):
+ # A child process died because of a signal.
returncode = -os.WTERMSIG(status)
elif os.WIFEXITED(status):
+ # A child process exited (e.g. sys.exit()).
returncode = os.WEXITSTATUS(status)
else:
- # shouldn't happen
- continue
+ # A child exited, but we don't understand its status.
+ # 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)
if transp is not None:
transp._process_exited(returncode)
@@ -480,18 +483,15 @@ class _UnixSubprocessTransport(transports.SubprocessTransport):
loop = self._loop
if proc.stdin is not None:
transp, proto = yield from loop.connect_write_pipe(
- functools.partial(
- _UnixWriteSubprocessPipeProto, self, STDIN),
+ lambda: _UnixWriteSubprocessPipeProto(self, STDIN),
proc.stdin)
if proc.stdout is not None:
transp, proto = yield from loop.connect_read_pipe(
- functools.partial(
- _UnixReadSubprocessPipeProto, self, STDOUT),
+ lambda: _UnixReadSubprocessPipeProto(self, STDOUT),
proc.stdout)
if proc.stderr is not None:
transp, proto = yield from loop.connect_read_pipe(
- functools.partial(
- _UnixReadSubprocessPipeProto, self, STDERR),
+ lambda: _UnixReadSubprocessPipeProto(self, STDERR),
proc.stderr)
if not self._pipes:
self._try_connected()
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 834df81..27e70c6 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -266,7 +266,7 @@ class SelectorEventLoopTests(unittest.TestCase):
self.loop._subprocesses[7] = transp
self.loop._sig_chld()
- self.assertFalse(transp._process_exited.called)
+ self.assertTrue(transp._process_exited.called)
self.assertFalse(m_WEXITSTATUS.called)
self.assertFalse(m_WTERMSIG.called)