Open
Description
Bug report
atexit
is throwing a SystemExit
exception and printing its traceback even though the documentation says that should not be true for SystemExit
.
If an exception is raised during execution of the exit handlers, a traceback is printed (unless SystemExit is raised) and the exception information is saved. After all exit handlers have had a chance to run, the last exception to be raised is re-raised.
I have identified that the issue is related to this PR: #23779 in which the exception flow was removed.
To reproduce:
Behavior with Python 3.6 up to 3.9:
$ docker run python:3.6 python -c "import atexit,sys;atexit.register(sys.exit)"; echo $?
0
With Python 3.10 and 3.11:
$ docker run python:3.10 python -c "import atexit,sys;atexit.register(sys.exit)"; echo $?
Exception ignored in atexit callback: <built-in function exit>
SystemExit:
0
With a bit more code you can see the traceback:
import atexit
import sys
def exit():
sys.exit()
atexit.register(exit)
Output:
$ python test.py
Exception ignored in atexit callback: <function exit at 0x1041c8040>
Traceback (most recent call last):
File "[...]/test.py", line 8, in exit
sys.exit()
SystemExit:
Your environment
Locally:
CPython: 3.10.10
OS: macOS Ventura 13.2.1
Intel processor
On Docker:
Image: python:3.10
Let me know if I can be of assistance.