I'd like to do a clean shutdown of a class that does one task when exiting normally, and not under something like exit(1). How can I determine the current exit code. Example:
import sys import atexit def myexit(): print("atexit") atexit.register(myexit) class Test(object): def __init(self): pass def __del__(self): print("here") # print(sys.exit_code) # How do I get this??? x = Test() exit(1) which produces:
atexit here But in neither of those places do I know how to get the exit code passed to sys.exit().
There was other answer but it doesn't seem wise to implement a forced wrapper from another reusable module.
__del__. There's no guarantee that it'll be called.__del__is called.SystemExit)?