Skip to content
Merged
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
26 changes: 15 additions & 11 deletions Lib/_bootsubprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
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
# calls subprocess.Popen().wait()
class Popen:
Expand All @@ -27,15 +36,8 @@ def wait(self):
os._exit(1)
else:
# Parent process
pid, status = os.waitpid(pid, 0)
if os.WIFSIGNALED(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}")
_, status = os.waitpid(pid, 0)
self.returncode = _waitstatus_to_exitcode(status)

return self.returncode

Expand Down Expand Up @@ -85,8 +87,10 @@ def check_output(cmd, **kwargs):
try:
# system() spawns a shell
status = os.system(cmd)
if status:
raise ValueError(f"Command {cmd!r} failed with status {status!r}")
exitcode = _waitstatus_to_exitcode(status)
if exitcode:
raise ValueError(f"Command {cmd!r} returned non-zero "
f"exit status {exitcode!r}")

try:
with open(tmp_filename, "rb") as fp:
Expand Down