Commits

anatoly techtonik  committed b19ebf4

Cleanup replacement of sys.exitfunc with atexit (Python 2+)

  • Participants
  • Parent commits e5aa21a

Comments (0)

Files changed (5)

File bin/scons-test.py

 # so that problems on different platforms can be identified sooner.
 #
 
+import atexit
 import getopt
 import imp
 import os
         import shutil
         os.chdir(startdir)
         shutil.rmtree(tempdir)
-    sys.exitfunc = cleanup
+    atexit.register(cleanup)
 
 # Fetch the input file if it happens to be across a network somewhere.
 # Ohmigod, does Python make this simple...

File src/engine/SCons/cppTests.py

 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
+import atexit
 import sys
 import unittest
 
         if os.path.exists(dir):
             shutil.rmtree(dir)
 
-sys.exitfunc = _clean
+atexit.register(_clean)
 
 class fileTestCase(unittest.TestCase):
     cpp_class = cpp.DumbPreProcessor

File src/engine/SCons/exitfuncs.py

 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 
+import atexit
 
 _exithandlers = []
 def _run_exitfuncs():
     """
     _exithandlers.append((func, targs, kargs))
 
-import sys
 
-try:
-    x = sys.exitfunc
-
-    # if x isn't our own exit func executive, assume it's another
-    # registered exit function - append it to our list...
-    if x != _run_exitfuncs:
-        register(x)
-
-except AttributeError:
-    pass
-
-# make our exit function get run by python when it exits:    
-sys.exitfunc = _run_exitfuncs
-
-del sys
+# make our exit function get run by python when it exits
+atexit.register(_run_exitfuncs)
 
 # Local Variables:
 # tab-width:4

File test/GetBuildFailures/parallel.py

     for bf in sorted(GetBuildFailures(), key=lambda t: t.filename):
         print "%%s failed:  %%s" %% (bf.node, bf.errstr)
 
-try:
-    import atexit
-except ImportError:
-    import sys
-    sys.exitfunc = print_build_failures
-else:
-    atexit.register(print_build_failures)
+import atexit
+atexit.register(print_build_failures)
 """ % locals())
 
 test.write('f3.in', "f3.in\n")

File test/GetBuildFailures/serial.py

         if bf.command:
             print "BF:    %%s" %% " ".join(Flatten(bf.command))
 
-try:
-    import atexit
-except ImportError:
-    import sys
-    sys.exitfunc = print_build_failures
-else:
-    atexit.register(print_build_failures)
+import atexit
+atexit.register(print_build_failures)
 """ % locals())
 
 test.write('f03.in', "f03.in\n")