I would like to print the exit code in a function registered by atexit
.
import atexit, sys, os
@atexit.register
def goodbye():
print('Exit code', sys.???)
My script loads some not-standard modules which may raise an exception or call exit() and in all cases I would like to write the exit code to a log file. I checked the sys
and os
modules, but I found no such attribute of method.
UPDATE
The issue is more complicated than I thought. For quit()
, exit()
and sys_exit()
atexit
function is called. Actually they can be called practically with anything! Their argument can be empty, number, text or any class, object and anything else and this value is in the args
argument of an SystemExit exception.
But not for os._exit(), os.abort(). They behaves more like the C exit()
and abort()
, but should not be used as the housekeeping activities would be skipped!