Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Commit fe0b17a

Browse files
author
Guido van Rossum
committed
If waitpid() returns a weird status, the process is still dead.
Also tidy up a few comment and replace functools.partial with lambda.
1 parent b1416df commit fe0b17a

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

asyncio/unix_events.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import collections
44
import errno
55
import fcntl
6-
import functools
76
import os
87
import signal
98
import socket
@@ -167,22 +166,26 @@ def _reg_sigchld(self):
167166

168167
def _sig_chld(self):
169168
try:
170-
# because of signal coalescing, we must keep calling waitpid() as
171-
# long as we're able to reap a child
169+
# Because of signal coalescing, we must keep calling waitpid() as
170+
# long as we're able to reap a child.
172171
while True:
173172
try:
174173
pid, status = os.waitpid(-1, os.WNOHANG)
175174
except ChildProcessError:
176-
break
175+
break # No more child processes exist.
177176
if pid == 0:
178-
break
177+
break # All remaining child processes are still alive.
179178
elif os.WIFSIGNALED(status):
179+
# A child process died because of a signal.
180180
returncode = -os.WTERMSIG(status)
181181
elif os.WIFEXITED(status):
182+
# A child process exited (e.g. sys.exit()).
182183
returncode = os.WEXITSTATUS(status)
183184
else:
184-
# shouldn't happen
185-
continue
185+
# A child exited, but we don't understand its status.
186+
# This shouldn't happen, but if it does, let's just
187+
# return that status; perhaps that helps debug it.
188+
returncode = status
186189
transp = self._subprocesses.get(pid)
187190
if transp is not None:
188191
transp._process_exited(returncode)
@@ -480,18 +483,15 @@ def _post_init(self):
480483
loop = self._loop
481484
if proc.stdin is not None:
482485
transp, proto = yield from loop.connect_write_pipe(
483-
functools.partial(
484-
_UnixWriteSubprocessPipeProto, self, STDIN),
486+
lambda: _UnixWriteSubprocessPipeProto(self, STDIN),
485487
proc.stdin)
486488
if proc.stdout is not None:
487489
transp, proto = yield from loop.connect_read_pipe(
488-
functools.partial(
489-
_UnixReadSubprocessPipeProto, self, STDOUT),
490+
lambda: _UnixReadSubprocessPipeProto(self, STDOUT),
490491
proc.stdout)
491492
if proc.stderr is not None:
492493
transp, proto = yield from loop.connect_read_pipe(
493-
functools.partial(
494-
_UnixReadSubprocessPipeProto, self, STDERR),
494+
lambda: _UnixReadSubprocessPipeProto(self, STDERR),
495495
proc.stderr)
496496
if not self._pipes:
497497
self._try_connected()

tests/test_unix_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def test__sig_chld_unknown_status(self, m_waitpid,
266266
self.loop._subprocesses[7] = transp
267267

268268
self.loop._sig_chld()
269-
self.assertFalse(transp._process_exited.called)
269+
self.assertTrue(transp._process_exited.called)
270270
self.assertFalse(m_WEXITSTATUS.called)
271271
self.assertFalse(m_WTERMSIG.called)
272272

0 commit comments

Comments
 (0)