diff options
Diffstat (limited to 'Lib/atexit.py')
-rw-r--r-- | Lib/atexit.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Lib/atexit.py b/Lib/atexit.py index 85ccb24..e109eb5 100644 --- a/Lib/atexit.py +++ b/Lib/atexit.py @@ -15,9 +15,22 @@ def _run_exitfuncs(): last in, first out. """ + exc_info = None while _exithandlers: func, targs, kargs = _exithandlers.pop() - func(*targs, **kargs) + try: + func(*targs, **kargs) + except SystemExit: + exc_info = sys.exc_info() + except: + import sys, traceback + print >> sys.stderr, "Error in atexit._run_exitfuncs:" + traceback.print_exc() + exc_info = sys.exc_info() + + if exc_info is not None: + raise exc_info[0], exc_info[1], exc_info[2] + def register(func, *targs, **kargs): """register a function to be executed upon normal program termination @@ -33,7 +46,6 @@ if hasattr(sys, "exitfunc"): # Assume it's another registered exit function - append it to our list register(sys.exitfunc) sys.exitfunc = _run_exitfuncs - del sys if __name__ == "__main__": |