GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • 3.3.1 atexit Example

This view

  • Original page
  • New address

GeezerVison is showing docs.python.org — 3.3 atexit -- Exit handlers

Previous Page Up One Level Next Page Python Library Reference Contents Module Index Index
Previous: 3.2 gc Up: 3. Python Runtime Services Next: 3.3.1 atexit Example

3.3 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.

See Also:

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


Subsections
  • 3.3.1 atexit Example


Previous Page Up One Level Next Page Python Library Reference Contents Module Index Index
Previous: 3.2 gc Up: 3. Python Runtime Services Next: 3.3.1 atexit Example

See About this document... for information on suggesting changes.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.