This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author graingert
Recipients graingert, gregory.p.smith, gvanrossum, ncoghlan
Date 2020-09-16.19:08:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1600283336.31.0.962711371894.issue41602@roundup.psfhosted.org>
In-reply-to
Content
The return code of python on linux when the program is ended with a KeyboardInterrupt should be -2, this works in most cases - except when called via "python -m"


Does this repl help?

Python 3.8.2 (default, Jul 16 2020, 14:00:26) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib, subprocess
>>> pathlib.Path("spam.py").write_text("raise KeyboardInterrupt")
23
>>> subprocess.run(["python3", "spam.py"])
Traceback (most recent call last):
  File "spam.py", line 1, in <module>
    raise KeyboardInterrupt
KeyboardInterrupt
CompletedProcess(args=['python3', 'spam.py'], returncode=-2)
>>> subprocess.run(["python3", "-m", "spam"])
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/graingert/projects/spam.py", line 1, in <module>
    raise KeyboardInterrupt
KeyboardInterrupt
CompletedProcess(args=['python3', '-m', 'spam'], returncode=1)
>>>
History
Date User Action Args
2020-09-16 19:08:56graingertsetrecipients: + graingert, gvanrossum, gregory.p.smith, ncoghlan
2020-09-16 19:08:56graingertsetmessageid: <1600283336.31.0.962711371894.issue41602@roundup.psfhosted.org>
2020-09-16 19:08:56graingertlinkissue41602 messages
2020-09-16 19:08:56graingertcreate