classification
Title: subprocess reports signal as negative exit status, not documented
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: dmacnet, gregory.p.smith, python-dev
Priority: normal Keywords:

Created on 2016-05-31 16:35 by dmacnet, last changed 2016-06-03 19:15 by gregory.p.smith. This issue is now closed.

Messages (7)
msg266758 - (view) Author: David MacKenzie (dmacnet) Date: 2016-05-31 16:35
If a command run by subprocess.check_call() exits because of a signal, e.g. SIGPIPE, Popen._handle_exitstatus() encodes the signal number as a negative return code. check_call() then raises that as a CalledProcessError, which describes it as "returned non-zero exit status -13". This is misleading and undocumented. 

CalledProcessError.__str__() should check if self.returncode is negative and if so return a string indicating that it was "signal 13", not "exit status -13". Better yet, it should include the descriptive name of the signal, e.g., SIGPIPE.

And, the documentation for the subprocess module should note that a signal is converted into a negative returncode.
msg266760 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2016-05-31 16:43
I'll take this as a documentation update for 3.5 and a feature request for better message text in 3.6.
msg267009 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2016-06-03 00:34
docs updated (7b12180481da and 19d77132f38d).

working on the error message update.
msg267052 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-06-03 06:14
New changeset f2d13349ea5d by Gregory P. Smith in branch 'default':
Issue #27167: Clarify the subprocess.CalledProcessError error message text
https://hg.python.org/cpython/rev/f2d13349ea5d
msg267055 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-06-03 06:19
New changeset 1022d09d11e5 by Gregory P. Smith in branch 'default':
issue27167: make the test not care about the exact signal name in the
https://hg.python.org/cpython/rev/1022d09d11e5
msg267056 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2016-06-03 06:24
So this is mostly done... one oddity which may warrant improvement though: signal numbers have multiple names.  ie: SIGABRT is also known as SIGIOT, etc.

This is likely to be confusing to if the error message is surfaced to the user as most users only know one common name rather than all of them as described in their system headers or the signal(7) man page.

I'd rather Python not be in the business of picking which name is more popular, but it can generate different error messages for the same signal across repeated runs due to hash randomization changing the order of the map in the signal.Signals type.

run  python3.5 -c 'import signal; print(signal.Signals(6))'  a handful of times to see this.
msg267140 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-06-03 19:15
New changeset 365b5e6163a6 by Gregory P. Smith in branch 'default':
signal, socket, and ssl module IntEnum constant name lookups now return a
https://hg.python.org/cpython/rev/365b5e6163a6
History
Date User Action Args
2016-06-03 19:15:46gregory.p.smithsetstatus: open -> closed
resolution: fixed
2016-06-03 19:15:03python-devsetmessages: + msg267140
2016-06-03 06:25:16gregory.p.smithsetversions: - Python 3.5
2016-06-03 06:24:51gregory.p.smithsetmessages: + msg267056
2016-06-03 06:19:47python-devsetmessages: + msg267055
2016-06-03 06:14:25python-devsetnosy: + python-dev
messages: + msg267052
2016-06-03 00:34:21gregory.p.smithsetmessages: + msg267009
2016-05-31 16:43:02gregory.p.smithsetversions: + Python 3.6
nosy: + gregory.p.smith

messages: + msg266760

assignee: gregory.p.smith
2016-05-31 16:35:00dmacnetcreate