Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / html / python / lib / module-atexit.html
CommitLineData
86530b38
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="next" href="module-types.html" />
13<link rel="prev" href="module-fpectl.html" />
14<link rel="parent" href="python.html" />
15<link rel="next" href="atexit-example.html" />
16<meta name='aesop' content='information' />
17<title>3.5 atexit -- Exit handlers</title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="3.4.2 Limitations and other"
25 href="node45.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="3. Python Runtime Services"
28 href="python.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="3.5.1 atexit Example"
31 href="atexit-example.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Library Reference</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
38 border='0' height='32' alt='Module Index' width='32' /></a></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="node45.html">3.4.2 Limitations and other</A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="atexit-example.html">3.5.1 atexit Example</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H1><A NAME="SECTION005500000000000000000">
563.5 <tt class="module">atexit</tt> --
57 Exit handlers</A>
58</H1>
59
60<P>
61<A NAME="module-atexit"></A>
62
63<P>
64
65<span class="versionnote">New in version 2.0.</span>
66
67<P>
68The <tt class="module">atexit</tt> module defines a single function to register
69cleanup functions. Functions thus registered are automatically
70executed upon normal interpreter termination.
71
72<P>
73Note: the functions registered via this module are not called when the program is killed by a
74signal, when a Python fatal internal error is detected, or when
75<tt class="function">os._exit()</tt> is called.
76
77<P>
78This is an alternate interface to the functionality provided by the
79<code>sys.exitfunc</code> variable.
80<a id='l2h-437' xml:id='l2h-437'></a>
81<P>
82Note: This module is unlikely to work correctly when used with other code
83that sets <code>sys.exitfunc</code>. In particular, other core Python modules are
84free to use <tt class="module">atexit</tt> without the programmer's knowledge. Authors who
85use <code>sys.exitfunc</code> should convert their code to use
86<tt class="module">atexit</tt> instead. The simplest way to convert code that sets
87<code>sys.exitfunc</code> is to import <tt class="module">atexit</tt> and register the function
88that had been bound to <code>sys.exitfunc</code>.
89
90<P>
91<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
92 <td><nobr><b><tt id='l2h-438' xml:id='l2h-438' class="function">register</tt></b>(</nobr></td>
93 <td><var>func</var><big>[</big><var>, *args</var><big>[</big><var>, **kargs</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
94<dd>
95Register <var>func</var> as a function to be executed at termination. Any
96optional arguments that are to be passed to <var>func</var> must be passed
97as arguments to <tt class="function">register()</tt>.
98
99<P>
100At normal program termination (for instance, if
101<tt class="function">sys.exit()</tt> is called or the main module's execution
102completes), all functions registered are called in last in, first out
103order. The assumption is that lower level modules will normally be
104imported before higher level modules and thus must be cleaned up
105later.
106
107<P>
108If an exception is raised during execution of the exit handlers, a
109traceback is printed (unless <tt class="exception">SystemExit</tt> is raised) and the
110exception information is saved. After all exit handlers have had a
111chance to run the last exception to be raised is re-raised.
112</dl>
113
114<P>
115<div class="seealso">
116 <p class="heading">See Also:</p>
117
118 <dl compact="compact" class="seemodule">
119 <dt>Module <b><tt class="module"><a href="module-readline.html">readline</a></tt>:</b>
120 <dd>Useful example of <tt class="module">atexit</tt> to read and
121 write <tt class="module"><a href="module-readline.html">readline</a></tt> history files.
122 </dl>
123</div>
124
125<P>
126
127<p><br /></p><hr class='online-navigation' />
128<div class='online-navigation'>
129<!--Table of Child-Links-->
130<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
131
132<UL CLASS="ChildLinks">
133<LI><A href="atexit-example.html">3.5.1 <tt class="module">atexit</tt> Example</a>
134</ul>
135<!--End of Table of Child-Links-->
136</div>
137
138<DIV CLASS="navigation">
139<div class='online-navigation'>
140<p></p><hr />
141<table align="center" width="100%" cellpadding="0" cellspacing="2">
142<tr>
143<td class='online-navigation'><a rel="prev" title="3.4.2 Limitations and other"
144 href="node45.html"><img src='../icons/previous.png'
145 border='0' height='32' alt='Previous Page' width='32' /></A></td>
146<td class='online-navigation'><a rel="parent" title="3. Python Runtime Services"
147 href="python.html"><img src='../icons/up.png'
148 border='0' height='32' alt='Up One Level' width='32' /></A></td>
149<td class='online-navigation'><a rel="next" title="3.5.1 atexit Example"
150 href="atexit-example.html"><img src='../icons/next.png'
151 border='0' height='32' alt='Next Page' width='32' /></A></td>
152<td align="center" width="100%">Python Library Reference</td>
153<td class='online-navigation'><a rel="contents" title="Table of Contents"
154 href="contents.html"><img src='../icons/contents.png'
155 border='0' height='32' alt='Contents' width='32' /></A></td>
156<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
157 border='0' height='32' alt='Module Index' width='32' /></a></td>
158<td class='online-navigation'><a rel="index" title="Index"
159 href="genindex.html"><img src='../icons/index.png'
160 border='0' height='32' alt='Index' width='32' /></A></td>
161</tr></table>
162<div class='online-navigation'>
163<b class="navlabel">Previous:</b>
164<a class="sectref" rel="prev" href="node45.html">3.4.2 Limitations and other</A>
165<b class="navlabel">Up:</b>
166<a class="sectref" rel="parent" href="python.html">3. Python Runtime Services</A>
167<b class="navlabel">Next:</b>
168<a class="sectref" rel="next" href="atexit-example.html">3.5.1 atexit Example</A>
169</div>
170</div>
171<hr />
172<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
173</DIV>
174<!--End of Navigation Panel-->
175<ADDRESS>
176See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
177</ADDRESS>
178</BODY>
179</HTML>