summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-12-16 11:11:24 (GMT)
committerGitHub <noreply@github.com>2020-12-16 11:11:24 (GMT)
commit99d28c56708bff1f442e1df5748adb2620542c61 (patch)
tree5af36d44fea2703337105c867cf69cfadc6eb61f /Lib/asyncio
parent5f0fe8ec70120f4586d08978b0911b436f82c421 (diff)
downloadcpython-99d28c56708bff1f442e1df5748adb2620542c61.zip
cpython-99d28c56708bff1f442e1df5748adb2620542c61.tar.gz
cpython-99d28c56708bff1f442e1df5748adb2620542c61.tar.bz2
bpo-40364: asyncio uses os.waitstatus_to_exitcode() (GH-23798)
test_unix_events.py no longer checks if waitstatus_to_exitcode() mock has been called or not to make the test more functional, rather than checking the exact implementation.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/unix_events.py34
1 files changed, 15 insertions, 19 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 1b57e34..33a6732 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -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.
@@ -941,7 +951,7 @@ class PidfdChildWatcher(AbstractChildWatcher):
" will report returncode 255",
pid)
else:
- returncode = _compute_returncode(status)
+ returncode = waitstatus_to_exitcode(status)
os.close(pidfd)
callback(pid, returncode, *args)
@@ -956,20 +966,6 @@ class PidfdChildWatcher(AbstractChildWatcher):
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):
@@ -1080,7 +1076,7 @@ class SafeChildWatcher(BaseChildWatcher):
# 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)
@@ -1173,7 +1169,7 @@ class FastChildWatcher(BaseChildWatcher):
# A child process is still alive.
return
- returncode = _compute_returncode(status)
+ returncode = waitstatus_to_exitcode(status)
with self._lock:
try:
@@ -1296,7 +1292,7 @@ class MultiLoopChildWatcher(AbstractChildWatcher):
# 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)
@@ -1399,7 +1395,7 @@ class ThreadedChildWatcher(AbstractChildWatcher):
"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)