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 Melebius
Recipients Melebius
Date 2016-05-16.07:57:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1463385428.15.0.762354704325.issue27035@psf.upfronthosting.co.za>
In-reply-to
Content
I want to set exit code of my script in a function registered in the atexit module. (See https://stackoverflow.com/q/37178636/711006.) Calling sys.exit() in that function results in the following error:

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "atexit_test.py", line 3, in myexit
    sys.exit(2)
SystemExit: 2

Despite the printed error, the exit code is set to 0. (This might be related with #1257.)

This problem seems to affect Python 3.x. I experienced it with Python 3.5.1 on Windows 7 x64 and I am able to reproduce it with Python 3.4.3 on Linux (x64). Python 2.7.6 on the same Linux machine works as expected: Exits without additional messages and the desired exit code is set.

A simple test case:

def myexit():
  import sys
  sys.exit(2)

import atexit
atexit.register(myexit)
History
Date User Action Args
2016-05-16 07:57:08Melebiussetrecipients: + Melebius
2016-05-16 07:57:08Melebiussetmessageid: <1463385428.15.0.762354704325.issue27035@psf.upfronthosting.co.za>
2016-05-16 07:57:08Melebiuslinkissue27035 messages
2016-05-16 07:57:07Melebiuscreate