ASPN ActiveState Programmer Network
  ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups | Web Services
SEARCH
advanced | search help

Reference
ActivePython 2.5
Python Documentation
Library Reference
26. Python Runtime Services
26.1 sys -- System-specific parameters and functions
26.2 builtin -- Built-in objects
26.3 main -- Top-level script environment
26.4 warnings -- Warning control
26.5 contextlib -- Utilities for with-statement contexts.
26.6 atexit -- Exit handlers
26.6.1 atexit Example
26.7 traceback -- Print or retrieve a stack traceback
26.8 future -- Future statement definitions
26.9 gc -- Garbage Collector interface
26.10 inspect -- Inspect live objects
26.11 site -- Site-specific configuration hook
26.12 user -- User-specific configuration hook
26.13 fpectl -- Floating point exception control

MyASPN >> Reference >> ActivePython 2.5 >> Python Documentation >> Library Reference >> 26. Python Runtime Services
ActivePython 2.5 documentation

26.6 atexit -- Exit handlers

New in version 2.0.

The atexit module defines a single function to register cleanup functions. Functions thus registered are automatically executed upon normal interpreter termination.

Note: the functions registered via this module are not called when the program is killed by a signal, when a Python fatal internal error is detected, or when os._exit() is called.

This is an alternate interface to the functionality provided by the sys.exitfunc variable.

Note: This module is unlikely to work correctly when used with other code that sets sys.exitfunc. In particular, other core Python modules are free to use atexit without the programmer's knowledge. Authors who use sys.exitfunc should convert their code to use atexit instead. The simplest way to convert code that sets sys.exitfunc is to import atexit and register the function that had been bound to sys.exitfunc.

register( func[, *args[, **kargs]])
Register func as a function to be executed at termination. Any optional arguments that are to be passed to func must be passed as arguments to register().

At normal program termination (for instance, if sys.exit() is called or the main module's execution completes), all functions registered are called in last in, first out order. The assumption is that lower level modules will normally be imported before higher level modules and thus must be cleaned up later.

If an exception is raised during execution of the exit handlers, a traceback is printed (unless SystemExit is raised) and the exception information is saved. After all exit handlers have had a chance to run the last exception to be raised is re-raised.

See Also:

Module readline:
Useful example of atexit to read and write readline history files.



See About this document... for information on suggesting changes.

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState 2004 All rights reserved