diff options
author | Skip Montanaro <skip@pobox.com> | 2004-11-04 04:31:30 (GMT) |
---|---|---|
committer | Skip Montanaro <skip@pobox.com> | 2004-11-04 04:31:30 (GMT) |
commit | 599bd5e1e16aaa3a7652d245b6b2a018e772a557 (patch) | |
tree | 0c2437879be035ea36812826af8cb6565ee2045f /Lib/atexit.py | |
parent | ed306292d68fe8ca3fb48f31129fe68229741519 (diff) | |
download | cpython-599bd5e1e16aaa3a7652d245b6b2a018e772a557.zip cpython-599bd5e1e16aaa3a7652d245b6b2a018e772a557.tar.gz cpython-599bd5e1e16aaa3a7652d245b6b2a018e772a557.tar.bz2 |
Fix bug 1052242. Also includes rewrite of test case using unittest and
avoiding use of popen.
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__": |