rest25/library/atexit.rst => rest262/library/atexit.rst
f1
2:mod:`atexit` --- Exit handlers
3===============================
4
5.. module:: atexit
6   :synopsis: Register and execute cleanup functions.
n7-.. moduleauthor:: Skip Montanaro <skip@mojam.com>
n7+.. moduleauthor:: Skip Montanaro <skip@pobox.com>
8-.. sectionauthor:: Skip Montanaro <skip@mojam.com>
8+.. sectionauthor:: Skip Montanaro <skip@pobox.com>
9
10
11.. versionadded:: 2.0
12
13The :mod:`atexit` module defines a single function to register cleanup
14functions.  Functions thus registered are automatically executed upon normal
15interpreter termination.
16
42   last in, first out order.  The assumption is that lower level modules will
43   normally be imported before higher level modules and thus must be cleaned up
44   later.
45
46   If an exception is raised during execution of the exit handlers, a traceback is
47   printed (unless :exc:`SystemExit` is raised) and the exception information is
48   saved.  After all exit handlers have had a chance to run the last exception to
49   be raised is re-raised.
n50+ 
51+   .. versionchanged:: 2.6
52+      This function now returns *func* which makes it possible to use it as a
53+      decorator without binding the original name to ``None``.
50
51
52.. seealso::
53
54   Module :mod:`readline`
55      Useful example of :mod:`atexit` to read and write :mod:`readline` history files.
56
57
87       print 'Goodbye, %s, it was %s to meet you.' % (name, adjective)
88
89   import atexit
90   atexit.register(goodbye, 'Donny', 'nice')
91
92   # or:
93   atexit.register(goodbye, adjective='nice', name='Donny')
94
t99+Usage as a :term:`decorator`::
100+ 
101+   import atexit
102+ 
103+   @atexit.register
104+   def goodbye():
105+       print "You are now leaving the Python sector."
106+ 
107+This obviously only works with functions that don't take arguments.
108+ 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op