Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions Lib/asyncio/unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ def _sighandler_noop(signum, frame):
pass


def waitstatus_to_exitcode(status):
try:
return os.waitstatus_to_exitcode(status)
except ValueError:
# The 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.
return status


class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
"""Unix event loop.

Expand Down Expand Up @@ -941,7 +951,7 @@ def _do_wait(self, pid):
" will report returncode 255",
pid)
else:
returncode = _compute_returncode(status)
returncode = waitstatus_to_exitcode(status)

os.close(pidfd)
callback(pid, returncode, *args)
Expand All @@ -956,20 +966,6 @@ def remove_child_handler(self, pid):
return True


def _compute_returncode(status):
if os.WIFSIGNALED(status):
# The child process died because of a signal.
return -os.WTERMSIG(status)
elif os.WIFEXITED(status):
# The child process exited (e.g sys.exit()).
return os.WEXITSTATUS(status)
else:
# The 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.
return status


class BaseChildWatcher(AbstractChildWatcher):

def __init__(self):
Expand Down Expand Up @@ -1080,7 +1076,7 @@ def _do_waitpid(self, expected_pid):
# The child process is still alive.
return

returncode = _compute_returncode(status)
returncode = waitstatus_to_exitcode(status)
if self._loop.get_debug():
logger.debug('process %s exited with returncode %s',
expected_pid, returncode)
Expand Down Expand Up @@ -1173,7 +1169,7 @@ def _do_waitpid_all(self):
# A child process is still alive.
return

returncode = _compute_returncode(status)
returncode = waitstatus_to_exitcode(status)

with self._lock:
try:
Expand Down Expand Up @@ -1296,7 +1292,7 @@ def _do_waitpid(self, expected_pid):
# The child process is still alive.
return

returncode = _compute_returncode(status)
returncode = waitstatus_to_exitcode(status)
debug_log = True
try:
loop, callback, args = self._callbacks.pop(pid)
Expand Down Expand Up @@ -1399,7 +1395,7 @@ def _do_waitpid(self, loop, expected_pid, callback, args):
"Unknown child process pid %d, will report returncode 255",
pid)
else:
returncode = _compute_returncode(status)
returncode = waitstatus_to_exitcode(status)
if loop.get_debug():
logger.debug('process %s exited with returncode %s',
expected_pid, returncode)
Expand Down
Loading