classification
Title: Different exit status when using -m
Type: behavior Stage: resolved
Components: Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, eric.araujo, jeffknupp, kisielk, ncoghlan, orsenthil, python-dev
Priority: normal Keywords: easy, patch

Created on 2012-06-07 21:13 by kisielk, last changed 2012-07-05 02:53 by orsenthil. This issue is now closed.

Files
File name Uploaded Description Edit
exit_code.patch jeffknupp, 2012-07-03 14:07 exit code patch review
Messages (7)
msg162501 - (view) Author: Kamil Kisiel (kisielk) Date: 2012-06-07 21:13
Python returns a different exit status when an exception is raised and -m is used as opposed to just running a module.

A short example, let's call it foo.py:

    def main():
        raise ValueError()

    if __name__ == '__main__':
        main()

When run with python foo.py the exit status of the process is 1. If run with python -mfoo the exit status of the process is 255.
msg162666 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-06-12 11:53
Technically, it returns -1 (which later gets coerced to an unsigned value).

However, there's no good reason for the inconsistency - the offending line (663) in main.c should be changed to be:

    sts = (RunModule(module, 1) != 0);

It is currently just:

    sts = RunModule(module, 1);

An additional test in test_cmd_line_script is also needed to ensure that both variants give a returncode of 1 in the future.
msg164602 - (view) Author: Jeff Knupp (jeffknupp) * Date: 2012-07-03 14:07
Fixed for 3.3. Does this need to be back ported as well?
msg164603 - (view) Author: Jeff Knupp (jeffknupp) * Date: 2012-07-03 14:08
And by 'Fixed' I of course meant 'Patched, awaiting review'.
msg164667 - (view) Author: Roundup Robot (python-dev) Date: 2012-07-05 02:33
New changeset fcbd3bda7c0f by Senthil Kumaran in branch '3.2':
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
http://hg.python.org/cpython/rev/fcbd3bda7c0f

New changeset 1186d68715cc by Senthil Kumaran in branch 'default':
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
http://hg.python.org/cpython/rev/1186d68715cc
msg164668 - (view) Author: Roundup Robot (python-dev) Date: 2012-07-05 02:50
New changeset 55b3de6d701e by Senthil Kumaran in branch '2.7':
Fix closes issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
http://hg.python.org/cpython/rev/55b3de6d701e
msg164669 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-07-05 02:53
Thanks for the patch Jeff and thanks for the guidance, Nick. 
Committed this in all branches.
History
Date User Action Args
2012-07-05 02:53:25orsenthilsetstatus: open -> closed

nosy: + orsenthil
messages: + msg164669

resolution: fixed
stage: patch review -> resolved
2012-07-05 02:50:44python-devsetmessages: + msg164668
2012-07-05 02:34:00python-devsetnosy: + python-dev
messages: + msg164667
2012-07-04 23:09:24Arfreversetnosy: + Arfrever
2012-07-03 20:56:28pitrousetstage: needs patch -> patch review
2012-07-03 14:08:38jeffknuppsetmessages: + msg164603
2012-07-03 14:07:46jeffknuppsetfiles: + exit_code.patch

nosy: + jeffknupp
messages: + msg164602

keywords: + patch
2012-07-02 20:53:15eric.araujosetkeywords: + easy
stage: needs patch
2012-06-12 11:53:56ncoghlansetmessages: + msg162666
2012-06-08 18:02:07eric.araujosetnosy: + ncoghlan, eric.araujo

versions: + Python 3.3, - Python 2.6
2012-06-07 21:13:38kisielkcreate