[issue45023] Python doesn't exit with proper resultcode on SIGINT in multiprocessing.Process

Amber Wright report at bugs.python.org
Thu Aug 26 18:56:33 EDT 2021


New submission from Amber Wright <ambwrig at gmail.com>:

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 at 3.9/bin/python3 -m test
Traceback (most recent call last):
  File "/usr/local/Cellar/python at 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 at 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 at 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 at 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

----------
components: Interpreter Core
files: test.py
messages: 400384
nosy: ambwrig
priority: normal
severity: normal
status: open
title: Python doesn't exit with proper resultcode on SIGINT in multiprocessing.Process
versions: Python 3.10, Python 3.11, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file50237/test.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45023>
_______________________________________


More information about the Python-bugs-list mailing list