Torsten Landschoff <t.landsch...@gmx.net> added the comment:

As this bug report clearly states this worked as documented in Python 2.7 and 
stopped working sometime in the Python 3 series.

I just ran into this while porting some code to Python 3 which uses an atexit 
handler to wind down some resources on process exit. This sometimes gets stuck 
and instead of hanging indefinitely the cleanup is aborted if it takes longer 
than a few seconds.

As this is actually an error, the registered exit function raises SystemExit to 
modify the exit code in this case. This used to work fine but does not 
anymore...

Observe:


## Python 2.7 works fine

$ sudo docker run python:2.7 python -c "import 
atexit,sys;atexit.register(sys.exit,124)"; echo $?
124

## Python 3.2 (oldest Python 3 on docker hub) swallows the exit code (but 
prints it)

$ sudo docker run python:3.2 python -c "import 
atexit,sys;atexit.register(sys.exit,124)"; echo $?
Error in atexit._run_exitfuncs:
SystemExit: 124
0

## Same for 3.3 up to 3.6

$ sudo docker run python:3.3 python -c "import 
atexit,sys;atexit.register(sys.exit,124)"; echo $?
Error in atexit._run_exitfuncs:
SystemExit: 124
0
$ sudo docker run python:3.5 python -c "import 
atexit,sys;atexit.register(sys.exit,124)"; echo $?
Error in atexit._run_exitfuncs:
SystemExit: 124
0

$ sudo docker run python:3.6 python -c "import 
atexit,sys;atexit.register(sys.exit,124)"; echo $?
Error in atexit._run_exitfuncs:
SystemExit: 124
0

## Python 3.7 swallows the exit code *and does not even print it*:

$ /opt/python-dev/bin/python3.7 -c "import 
atexit,sys;atexit.register(sys.exit,124)"; echo $?
0

----------
nosy: +torsten
type: enhancement -> behavior

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue27035>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to