]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF bug #1083202: UnboundLocalError raised by atexit module
authorRaymond Hettinger <python@rcn.com>
Sat, 11 Dec 2004 02:53:27 +0000 (02:53 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 11 Dec 2004 02:53:27 +0000 (02:53 +0000)
The sys module could be called before being imported.

Lib/atexit.py
Misc/NEWS

index e109eb590da7eb0c3723eca3c381ce5e0778f631..c9f4cc677528a7822f71860f34c16d1ceeb10974 100644 (file)
@@ -7,6 +7,8 @@ One public function, register, is defined.
 
 __all__ = ["register"]
 
+import sys
+
 _exithandlers = []
 def _run_exitfuncs():
     """run any registered exit functions
@@ -23,7 +25,7 @@ def _run_exitfuncs():
         except SystemExit:
             exc_info = sys.exc_info()
         except:
-            import sys, traceback
+            import traceback
             print >> sys.stderr, "Error in atexit._run_exitfuncs:"
             traceback.print_exc()
             exc_info = sys.exc_info()
@@ -41,12 +43,10 @@ def register(func, *targs, **kargs):
     """
     _exithandlers.append((func, targs, kargs))
 
-import sys
 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__":
     def x1():
index afc742fa2d1f9ccc575c98a88e70be91cee29e43..01d157cb403890344d9aab414ad32d3769aacf75 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,9 @@ Core and builtins
 Library
 -------
 
+- atexit.register no longer references the sys module before importing it.
+  (Bug #1083202).
+
 - unittest.TestCase.run() and unittest.TestSuite.run() can now be successfully
   extended or overridden by subclasses.  Formerly, the subclassed method would
   be ignored by the rest of the module.  (Bug #1078905).