Fix bug 1052242. Also includes rewrite of test case using unittest and

avoiding use of popen.
This commit is contained in:
Skip Montanaro 2004-11-04 04:31:30 +00:00
parent ed306292d6
commit 599bd5e1e1
4 changed files with 117 additions and 54 deletions

View file

@ -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__":