From e7b9e30c3f5e4b80c4506bb0eb2fe5847c2ac2f8 Mon Sep 17 00:00:00 2001 From: anatoly techtonik Date: Wed, 19 Dec 2012 22:41:31 +0300 Subject: Cleanup replacement of sys.exitfunc with atexit (Python 2+) --- bin/scons-test.py | 3 ++- src/engine/SCons/cppTests.py | 3 ++- src/engine/SCons/exitfuncs.py | 19 +++---------------- test/GetBuildFailures/parallel.py | 9 ++------- test/GetBuildFailures/serial.py | 9 ++------- 5 files changed, 11 insertions(+), 32 deletions(-) diff --git a/bin/scons-test.py b/bin/scons-test.py index 2191532..046cf4b 100644 --- a/bin/scons-test.py +++ b/bin/scons-test.py @@ -15,6 +15,7 @@ # so that problems on different platforms can be identified sooner. # +import atexit import getopt import imp import os @@ -74,7 +75,7 @@ if not os.path.exists(tempdir): 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... diff --git a/src/engine/SCons/cppTests.py b/src/engine/SCons/cppTests.py index bfb0b46..2f2025b 100644 --- a/src/engine/SCons/cppTests.py +++ b/src/engine/SCons/cppTests.py @@ -23,6 +23,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import atexit import sys import unittest @@ -608,7 +609,7 @@ def _clean(): if os.path.exists(dir): shutil.rmtree(dir) -sys.exitfunc = _clean +atexit.register(_clean) class fileTestCase(unittest.TestCase): cpp_class = cpp.DumbPreProcessor diff --git a/src/engine/SCons/exitfuncs.py b/src/engine/SCons/exitfuncs.py index 250dd54..7d00df7 100644 --- a/src/engine/SCons/exitfuncs.py +++ b/src/engine/SCons/exitfuncs.py @@ -30,6 +30,7 @@ Register functions which are executed when SCons exits for any reason. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import atexit _exithandlers = [] def _run_exitfuncs(): @@ -52,23 +53,9 @@ def register(func, *targs, **kargs): """ _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 diff --git a/test/GetBuildFailures/parallel.py b/test/GetBuildFailures/parallel.py index e250486..b7576af 100644 --- a/test/GetBuildFailures/parallel.py +++ b/test/GetBuildFailures/parallel.py @@ -82,13 +82,8 @@ def print_build_failures(): 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") diff --git a/test/GetBuildFailures/serial.py b/test/GetBuildFailures/serial.py index 752b348..9c56bb1 100644 --- a/test/GetBuildFailures/serial.py +++ b/test/GetBuildFailures/serial.py @@ -95,13 +95,8 @@ def print_build_failures(): 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") -- cgit v0.12