summaryrefslogtreecommitdiff
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorGregory P. Smith ext:(%20%5BGoogle%20Inc.%5D) <greg@krypto.org>2016-06-03 06:14:06 +0000
committerGregory P. Smith ext:(%20%5BGoogle%20Inc.%5D) <greg@krypto.org>2016-06-03 06:14:06 +0000
commitd6da7604d3eb19635f27e3d2d66e5a973cc26266 (patch)
treebcb7ec20810521ed6763b4fa1ad6f304d1bcde94 /Lib/subprocess.py
parent287e687648c5a443a11393d8311c83ed01e586e4 (diff)
downloadcpython-git-d6da7604d3eb19635f27e3d2d66e5a973cc26266.tar.gz
Issue #27167: Clarify the subprocess.CalledProcessError error message text
when the child process died due to a signal.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index b853f4d593..716f7fff53 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -372,9 +372,11 @@ class SubprocessError(Exception): pass
class CalledProcessError(SubprocessError):
- """This exception is raised when a process run by check_call() or
- check_output() returns a non-zero exit status.
- The exit status will be stored in the returncode attribute;
+ """Raised when a check_call() or check_output() process returns non-zero.
+
+ The exit status will be stored in the returncode attribute, negative
+ if it represents a signal number.
+
check_output() will also store the output in the output attribute.
"""
def __init__(self, returncode, cmd, output=None, stderr=None):
@@ -384,7 +386,16 @@ class CalledProcessError(SubprocessError):
self.stderr = stderr
def __str__(self):
- return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
+ if self.returncode and self.returncode < 0:
+ try:
+ return "Command '%s' died with %r." % (
+ self.cmd, signal.Signals(-self.returncode))
+ except ValueError:
+ return "Command '%s' died with unknown signal %d." % (
+ self.cmd, -self.returncode)
+ else:
+ return "Command '%s' returned non-zero exit status %d." % (
+ self.cmd, self.returncode)
@property
def stdout(self):