mirror of
https://github.com/python/cpython.git
synced 2025-12-08 02:08:20 +00:00
bpo-40094: Add _bootsubprocess._waitstatus_to_exitcode (GH-19264)
* Add _waitstatus_to_exitcode() helper function to _bootsubprocess. * Enhance check_output() error message if the command fails. _bootsubprocess no longer handles WIFSTOPPED() case: it now raises a ValueError.
This commit is contained in:
parent
2c003eff8f
commit
40bfdb1594
1 changed files with 15 additions and 11 deletions
|
|
@ -6,6 +6,15 @@ subprocess is unavailable. setup.py is not used on Windows.
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def _waitstatus_to_exitcode(status):
|
||||||
|
if os.WIFEXITED(status):
|
||||||
|
return os.WEXITSTATUS(status)
|
||||||
|
elif os.WIFSIGNALED(status):
|
||||||
|
return -os.WTERMSIG(status)
|
||||||
|
else:
|
||||||
|
raise ValueError(f"invalid wait status: {status!r}")
|
||||||
|
|
||||||
|
|
||||||
# distutils.spawn used by distutils.command.build_ext
|
# distutils.spawn used by distutils.command.build_ext
|
||||||
# calls subprocess.Popen().wait()
|
# calls subprocess.Popen().wait()
|
||||||
class Popen:
|
class Popen:
|
||||||
|
|
@ -27,15 +36,8 @@ class Popen:
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
else:
|
else:
|
||||||
# Parent process
|
# Parent process
|
||||||
pid, status = os.waitpid(pid, 0)
|
_, status = os.waitpid(pid, 0)
|
||||||
if os.WIFSIGNALED(status):
|
self.returncode = _waitstatus_to_exitcode(status)
|
||||||
self.returncode = -os.WTERMSIG(status)
|
|
||||||
elif os.WIFEXITED(status):
|
|
||||||
self.returncode = os.WEXITSTATUS(status)
|
|
||||||
elif os.WIFSTOPPED(status):
|
|
||||||
self.returncode = -os.WSTOPSIG(status)
|
|
||||||
else:
|
|
||||||
raise Exception(f"unknown child process exit status: {status!r}")
|
|
||||||
|
|
||||||
return self.returncode
|
return self.returncode
|
||||||
|
|
||||||
|
|
@ -85,8 +87,10 @@ def check_output(cmd, **kwargs):
|
||||||
try:
|
try:
|
||||||
# system() spawns a shell
|
# system() spawns a shell
|
||||||
status = os.system(cmd)
|
status = os.system(cmd)
|
||||||
if status:
|
exitcode = _waitstatus_to_exitcode(status)
|
||||||
raise ValueError(f"Command {cmd!r} failed with status {status!r}")
|
if exitcode:
|
||||||
|
raise ValueError(f"Command {cmd!r} returned non-zero "
|
||||||
|
f"exit status {exitcode!r}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(tmp_filename, "rb") as fp:
|
with open(tmp_filename, "rb") as fp:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue