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 torsten
Recipients Melebius, glyph, gwk, r.david.murray, torsten
Date 2017-11-27.12:01:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1511784115.7.0.213398074469.issue27035@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2017-11-27 12:01:55torstensetrecipients: + torsten, glyph, r.david.murray, gwk, Melebius
2017-11-27 12:01:55torstensetmessageid: <1511784115.7.0.213398074469.issue27035@psf.upfronthosting.co.za>
2017-11-27 12:01:55torstenlinkissue27035 messages
2017-11-27 12:01:55torstencreate