diff options
author | Victor Stinner <vstinner@python.org> | 2020-04-01 16:49:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-01 16:49:29 (GMT) |
commit | 65a796e5272f61b42792d3a8c69686558c1872c5 (patch) | |
tree | 138d64a8dd04ab4d1cac2eb5c415aa10e0bbe00f /Lib/multiprocessing | |
parent | 5dd836030e0e399b21ab0865ae0d93934bdb3930 (diff) | |
download | cpython-65a796e5272f61b42792d3a8c69686558c1872c5.zip cpython-65a796e5272f61b42792d3a8c69686558c1872c5.tar.gz cpython-65a796e5272f61b42792d3a8c69686558c1872c5.tar.bz2 |
bpo-40094: Add os.waitstatus_to_exitcode() (GH-19201)
Add os.waitstatus_to_exitcode() function to convert a wait status to an
exitcode.
Suggest waitstatus_to_exitcode() usage in the documentation when
appropriate.
Use waitstatus_to_exitcode() in:
* multiprocessing, os, subprocess and _bootsubprocess modules;
* test.support.wait_process();
* setup.py: run_command();
* and many tests.
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r-- | Lib/multiprocessing/forkserver.py | 10 | ||||
-rw-r--r-- | Lib/multiprocessing/popen_fork.py | 6 |
2 files changed, 3 insertions, 13 deletions
diff --git a/Lib/multiprocessing/forkserver.py b/Lib/multiprocessing/forkserver.py index 215ac39..22a911a 100644 --- a/Lib/multiprocessing/forkserver.py +++ b/Lib/multiprocessing/forkserver.py @@ -237,14 +237,8 @@ def main(listener_fd, alive_r, preload, main_path=None, sys_path=None): break child_w = pid_to_fd.pop(pid, None) if child_w is not None: - if os.WIFSIGNALED(sts): - returncode = -os.WTERMSIG(sts) - else: - if not os.WIFEXITED(sts): - raise AssertionError( - "Child {0:n} status is {1:n}".format( - pid,sts)) - returncode = os.WEXITSTATUS(sts) + returncode = os.waitstatus_to_exitcode(sts) + # Send exit code to client process try: write_signed(child_w, returncode) diff --git a/Lib/multiprocessing/popen_fork.py b/Lib/multiprocessing/popen_fork.py index a65b06f..625981c 100644 --- a/Lib/multiprocessing/popen_fork.py +++ b/Lib/multiprocessing/popen_fork.py @@ -30,11 +30,7 @@ class Popen(object): # e.errno == errno.ECHILD == 10 return None if pid == self.pid: - if os.WIFSIGNALED(sts): - self.returncode = -os.WTERMSIG(sts) - else: - assert os.WIFEXITED(sts), "Status is {:n}".format(sts) - self.returncode = os.WEXITSTATUS(sts) + self.returncode = os.waitstatus_to_exitcode(sts) return self.returncode def wait(self, timeout=None): |