Changeset 391 for python/trunk/Doc/library/atexit.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/atexit.rst
r2 r391 1 2 1 :mod:`atexit` --- Exit handlers 3 2 =============================== … … 11 10 .. versionadded:: 2.0 12 11 12 **Source code:** :source:`Lib/atexit.py` 13 14 -------------- 15 13 16 The :mod:`atexit` module defines a single function to register cleanup 14 17 functions. Functions thus registered are automatically executed upon normal 15 interpreter termination. 18 interpreter termination. :mod:`atexit` runs these functions in the *reverse* 19 order in which they were registered; if you register ``A``, ``B``, and ``C``, 20 at interpreter termination time they will be run in the order ``C``, ``B``, 21 ``A``. 16 22 17 Note: the functions registered via this module are not called when the program 18 is killed by a signal, when a Python fatal internal error is detected, or when 19 :func:`os._exit` is called.23 **Note:** The functions registered via this module are not called when the 24 program is killed by a signal not handled by Python, when a Python fatal 25 internal error is detected, or when :func:`os._exit` is called. 20 26 21 27 .. index:: single: exitfunc (in sys) 22 28 23 29 This is an alternate interface to the functionality provided by the 24 ``sys.exitfunc`` variable.30 :func:`sys.exitfunc` variable. 25 31 26 32 Note: This module is unlikely to work correctly when used with other code that … … 36 42 Register *func* as a function to be executed at termination. Any optional 37 43 arguments that are to be passed to *func* must be passed as arguments to 38 :func:`register`. 44 :func:`register`. It is possible to register the same function and arguments 45 more than once. 39 46 40 47 At normal program termination (for instance, if :func:`sys.exit` is called or … … 50 57 51 58 .. versionchanged:: 2.6 52 This function now returns *func* which makes it possible to use it as a53 decorator without binding the original name to ``None``.59 This function now returns *func*, which makes it possible to use it as a 60 decorator. 54 61 55 62 … … 71 78 72 79 try: 73 _count = int(open(" /tmp/counter").read())80 _count = int(open("counter").read()) 74 81 except IOError: 75 82 _count = 0 … … 80 87 81 88 def savecounter(): 82 open(" /tmp/counter", "w").write("%d" % _count)89 open("counter", "w").write("%d" % _count) 83 90 84 91 import atexit … … 105 112 print "You are now leaving the Python sector." 106 113 107 This obviously only works with functions that don't take arguments. 108 114 This only works with functions that can be called without arguments.
Note:
See TracChangeset
for help on using the changeset viewer.