[issue27155] '-' sign typo in example

2016-05-29 Thread Ben Kane

New submission from Ben Kane:

On page https://docs.python.org/3/library/subprocess.html#replacing-os-system

it looks like the code in the realistic example has a spurious '-' sign.
The line:

print("Child was terminated by signal", -retcode, file=sys.stderr)

shouldn't have the minus sign negating the retcode:

print("Child was terminated by signal", retcode, file=sys.stderr)

Full code in the example:

try:
retcode = call("mycmd" + " myarg", shell=True)
if retcode < 0:
print("Child was terminated by signal", -retcode, file=sys.stderr)
else:
print("Child returned", retcode, file=sys.stderr)
except OSError as e:
print("Execution failed:", e, file=sys.stderr)

should be:

try:
retcode = call("mycmd" + " myarg", shell=True)
if retcode < 0:
print("Child was terminated by signal", retcode, file=sys.stderr)
else:
print("Child returned", retcode, file=sys.stderr)
except OSError as e:
print("Execution failed:", e, file=sys.stderr)

Thanks, and apologies if I erred somewhere in this report.

--
assignee: docs@python
components: Documentation
messages: 266614
nosy: Ben Kane, docs@python
priority: normal
severity: normal
status: open
title: '-' sign typo in example
type: behavior
versions: Python 3.5

___
Python tracker 
<http://bugs.python.org/issue27155>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27155] '-' sign typo in example

2016-05-30 Thread Ben Kane

Ben Kane added the comment:

https://docs.python.org/3/library/subprocess.html#subprocess.Popen.returncode

does mention the negativeness about returncode in conjunction with POSIX 
signals. It would be helpful to mention this Python-specific (I think) behavior 
in a comment. 
However, returncode can also be set by poll() and wait(), which can also return 
errors. In the more realistic example, I would appreciate code that handles 
those errors as well (a check for returncode > 0), or a comment detailing that 
other errors aren't handled. I copied that code into mine, and didn't consider 
those cases initially, because "realistic" was in the description.

--

___
Python tracker 
<http://bugs.python.org/issue27155>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com