Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subprocess reports signal as negative exit status, not documented #71354

Closed
dmacnet mannequin opened this issue May 31, 2016 · 7 comments
Closed

subprocess reports signal as negative exit status, not documented #71354

dmacnet mannequin opened this issue May 31, 2016 · 7 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@dmacnet
Copy link
Mannequin

dmacnet mannequin commented May 31, 2016

BPO 27167
Nosy @gpshead, @dmacnet

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/gpshead'
closed_at = <Date 2016-06-03.19:15:46.718>
created_at = <Date 2016-05-31.16:35:00.419>
labels = ['type-bug', 'library']
title = 'subprocess reports signal as negative exit status, not documented'
updated_at = <Date 2016-06-03.19:15:46.717>
user = 'https://github.com/dmacnet'

bugs.python.org fields:

activity = <Date 2016-06-03.19:15:46.717>
actor = 'gregory.p.smith'
assignee = 'gregory.p.smith'
closed = True
closed_date = <Date 2016-06-03.19:15:46.718>
closer = 'gregory.p.smith'
components = ['Library (Lib)']
creation = <Date 2016-05-31.16:35:00.419>
creator = 'dmacnet'
dependencies = []
files = []
hgrepos = []
issue_num = 27167
keywords = []
message_count = 7.0
messages = ['266758', '266760', '267009', '267052', '267055', '267056', '267140']
nosy_count = 3.0
nosy_names = ['gregory.p.smith', 'python-dev', 'dmacnet']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue27167'
versions = ['Python 3.6']

@dmacnet
Copy link
Mannequin Author

dmacnet mannequin commented May 31, 2016

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.

@dmacnet dmacnet mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 31, 2016
@gpshead
Copy link
Member

gpshead commented May 31, 2016

I'll take this as a documentation update for 3.5 and a feature request for better message text in 3.6.

@gpshead gpshead self-assigned this May 31, 2016
@gpshead
Copy link
Member

gpshead commented Jun 3, 2016

docs updated (7b12180481da and 19d77132f38d).

working on the error message update.

@python-dev
Copy link
Mannequin

python-dev mannequin commented Jun 3, 2016

New changeset f2d13349ea5d by Gregory P. Smith in branch 'default':
Issue bpo-27167: Clarify the subprocess.CalledProcessError error message text
https://hg.python.org/cpython/rev/f2d13349ea5d

@python-dev
Copy link
Mannequin

python-dev mannequin commented Jun 3, 2016

New changeset 1022d09d11e5 by Gregory P. Smith in branch 'default':
bpo-27167: make the test not care about the exact signal name in the
https://hg.python.org/cpython/rev/1022d09d11e5

@gpshead
Copy link
Member

gpshead commented Jun 3, 2016

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.

@python-dev
Copy link
Mannequin

python-dev mannequin commented Jun 3, 2016

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

@gpshead gpshead closed this as completed Jun 3, 2016
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant