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.

classification
Title: Python doesn't exit with proper resultcode on SIGINT in multiprocessing.Process
Type: Stage:
Components: Interpreter Core Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ambwrig
Priority: normal Keywords:

Created on 2021-08-26 22:56 by ambwrig, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
test.py ambwrig, 2021-08-26 22:56 reproducible example
Messages (1)
msg400384 - (view) Author: Amber Wright (ambwrig) * Date: 2021-08-26 22:56
The return code of python on linux/MacOS when the program is ended with a KeyboardInterrupt should be -2, when running with multiprocessing the exitcode is 1. I've attached a reproduced example. 

From The Process.join() docs: https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Process.exitcode

> A negative value -N indicates that the child was terminated by signal N.

output:

$ /usr/local/opt/python@3.9/bin/python3 -m test
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/awright/docker/2108/test.py", line 49, in <module>
    sys.exit(main())
  File "/Users/awright/docker/2108/test.py", line 41, in main
    return target()
  File "/Users/awright/docker/2108/test.py", line 10, in target
    time.sleep(99999)
KeyboardInterrupt
proc.wait()=-2
Process SpawnProcess-1:
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/awright/docker/2108/test.py", line 10, in target
    time.sleep(99999)
KeyboardInterrupt
proc.exitcode=1



See also: 
https://bugs.python.org/issue1054041 and https://bugs.python.org/issue41602
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89186
2021-08-26 22:56:33ambwrigcreate