summaryrefslogtreecommitdiffstats
path: root/Lib/atexit.py
diff options
context:
space:
mode:
authorCollin Winter <collinw@gmail.com>2007-03-21 02:57:17 (GMT)
committerCollin Winter <collinw@gmail.com>2007-03-21 02:57:17 (GMT)
commit670e6921349dd408b6958a0c5d3b1486725f9beb (patch)
tree719d6b0e5348693a2d985dfabc5e9160f7f79108 /Lib/atexit.py
parent450ee81b227b093eeb0b7a933fe6ddc6dc768d4a (diff)
downloadcpython-670e6921349dd408b6958a0c5d3b1486725f9beb.zip
cpython-670e6921349dd408b6958a0c5d3b1486725f9beb.tar.gz
cpython-670e6921349dd408b6958a0c5d3b1486725f9beb.tar.bz2
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Diffstat (limited to 'Lib/atexit.py')
-rw-r--r--Lib/atexit.py65
1 files changed, 0 insertions, 65 deletions
diff --git a/Lib/atexit.py b/Lib/atexit.py
deleted file mode 100644
index 51a153e..0000000
--- a/Lib/atexit.py
+++ /dev/null
@@ -1,65 +0,0 @@
-"""
-atexit.py - allow programmer to define multiple exit functions to be executed
-upon normal program termination.
-
-One public function, register, is defined.
-"""
-
-__all__ = ["register"]
-
-import sys
-
-_exithandlers = []
-def _run_exitfuncs():
- """run any registered exit functions
-
- _exithandlers is traversed in reverse order so functions are executed
- last in, first out.
- """
-
- exc_info = None
- while _exithandlers:
- func, targs, kargs = _exithandlers.pop()
- try:
- func(*targs, **kargs)
- except SystemExit:
- exc_info = sys.exc_info()
- except:
- import traceback
- print("Error in atexit._run_exitfuncs:", file=sys.stderr)
- 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
-
- func - function to be called at exit
- targs - optional arguments to pass to func
- kargs - optional keyword arguments to pass to func
-
- func is returned to facilitate usage as a decorator.
- """
- _exithandlers.append((func, targs, kargs))
- return func
-
-if hasattr(sys, "exitfunc"):
- # Assume it's another registered exit function - append it to our list
- register(sys.exitfunc)
-sys.exitfunc = _run_exitfuncs
-
-if __name__ == "__main__":
- def x1():
- print("running x1")
- def x2(n):
- print("running x2(%r)" % (n,))
- def x3(n, kwd=None):
- print("running x3(%r, kwd=%r)" % (n, kwd))
-
- register(x1)
- register(x2, 12)
- register(x3, 5, "bar")
- register(x3, "no kwd args")