Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / lib / inspect-stack.html
CommitLineData
920dae64
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="prev" href="inspect-classes-functions.html" />
13<link rel="parent" href="module-inspect.html" />
14<link rel="next" href="module-traceback.html" />
15<meta name='aesop' content='information' />
16<title>3.11.4 The interpreter stack </title>
17</head>
18<body>
19<DIV CLASS="navigation">
20<div id='top-navigation-panel' xml:id='top-navigation-panel'>
21<table align="center" width="100%" cellpadding="0" cellspacing="2">
22<tr>
23<td class='online-navigation'><a rel="prev" title="3.11.3 Classes and functions"
24 href="inspect-classes-functions.html"><img src='../icons/previous.png'
25 border='0' height='32' alt='Previous Page' width='32' /></A></td>
26<td class='online-navigation'><a rel="parent" title="3.11 inspect "
27 href="module-inspect.html"><img src='../icons/up.png'
28 border='0' height='32' alt='Up One Level' width='32' /></A></td>
29<td class='online-navigation'><a rel="next" title="3.12 traceback "
30 href="module-traceback.html"><img src='../icons/next.png'
31 border='0' height='32' alt='Next Page' width='32' /></A></td>
32<td align="center" width="100%">Python Library Reference</td>
33<td class='online-navigation'><a rel="contents" title="Table of Contents"
34 href="contents.html"><img src='../icons/contents.png'
35 border='0' height='32' alt='Contents' width='32' /></A></td>
36<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
37 border='0' height='32' alt='Module Index' width='32' /></a></td>
38<td class='online-navigation'><a rel="index" title="Index"
39 href="genindex.html"><img src='../icons/index.png'
40 border='0' height='32' alt='Index' width='32' /></A></td>
41</tr></table>
42<div class='online-navigation'>
43<b class="navlabel">Previous:</b>
44<a class="sectref" rel="prev" href="inspect-classes-functions.html">3.11.3 Classes and functions</A>
45<b class="navlabel">Up:</b>
46<a class="sectref" rel="parent" href="module-inspect.html">3.11 inspect </A>
47<b class="navlabel">Next:</b>
48<a class="sectref" rel="next" href="module-traceback.html">3.12 traceback </A>
49</div>
50<hr /></div>
51</DIV>
52<!--End of Navigation Panel-->
53
54<H2><A NAME="SECTION0051140000000000000000"></A><A NAME="inspect-stack"></A>
55<BR>
563.11.4 The interpreter stack
57
58</H2>
59
60<P>
61When the following functions return ``frame records,'' each record
62is a tuple of six items: the frame object, the filename,
63the line number of the current line, the function name, a list of
64lines of context from the source code, and the index of the current
65line within that list.
66
67<P>
68<div class="warning"><b class="label">Warning:</b>
69
70Keeping references to frame objects, as found in
71the first element of the frame records these functions return, can
72cause your program to create reference cycles. Once a reference cycle
73has been created, the lifespan of all objects which can be accessed
74from the objects which form the cycle can become much longer even if
75Python's optional cycle detector is enabled. If such cycles must be
76created, it is important to ensure they are explicitly broken to avoid
77the delayed destruction of objects and increased memory consumption
78which occurs.
79
80<P>
81Though the cycle detector will catch these, destruction of the frames
82(and local variables) can be made deterministic by removing the cycle
83in a <tt class="keyword">finally</tt> clause. This is also important if the cycle
84detector was disabled when Python was compiled or using
85<tt class="function"><tt class="module"><a href="module-gc.html">gc</a></tt>.disable()</tt>. For example:
86
87<P>
88<div class="verbatim"><pre>
89def handle_stackframe_without_leak():
90 frame = inspect.currentframe()
91 try:
92 # do something with the frame
93 finally:
94 del frame
95</pre></div>
96</div>
97
98<P>
99The optional <var>context</var> argument supported by most of these
100functions specifies the number of lines of context to return, which
101are centered around the current line.
102
103<P>
104<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
105 <td><nobr><b><tt id='l2h-598' xml:id='l2h-598' class="function">getframeinfo</tt></b>(</nobr></td>
106 <td><var>frame</var><big>[</big><var>, context</var><big>]</big><var></var>)</td></tr></table></dt>
107<dd>
108 Get information about a frame or traceback object. A 5-tuple
109 is returned, the last five elements of the frame's frame record.
110</dl>
111
112<P>
113<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
114 <td><nobr><b><tt id='l2h-599' xml:id='l2h-599' class="function">getouterframes</tt></b>(</nobr></td>
115 <td><var>frame</var><big>[</big><var>, context</var><big>]</big><var></var>)</td></tr></table></dt>
116<dd>
117 Get a list of frame records for a frame and all outer frames. These
118 frames represent the calls that lead to the creation of <var>frame</var>.
119 The first entry in the returned list represents <var>frame</var>; the
120 last entry represents the outermost call on <var>frame</var>'s stack.
121</dl>
122
123<P>
124<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
125 <td><nobr><b><tt id='l2h-600' xml:id='l2h-600' class="function">getinnerframes</tt></b>(</nobr></td>
126 <td><var>traceback</var><big>[</big><var>, context</var><big>]</big><var></var>)</td></tr></table></dt>
127<dd>
128 Get a list of frame records for a traceback's frame and all inner
129 frames. These frames represent calls made as a consequence of
130 <var>frame</var>. The first entry in the list represents
131 <var>traceback</var>; the last entry represents where the exception was
132 raised.
133</dl>
134
135<P>
136<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
137 <td><nobr><b><tt id='l2h-601' xml:id='l2h-601' class="function">currentframe</tt></b>(</nobr></td>
138 <td><var></var>)</td></tr></table></dt>
139<dd>
140 Return the frame object for the caller's stack frame.
141</dl>
142
143<P>
144<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
145 <td><nobr><b><tt id='l2h-602' xml:id='l2h-602' class="function">stack</tt></b>(</nobr></td>
146 <td><var></var><big>[</big><var>context</var><big>]</big><var></var>)</td></tr></table></dt>
147<dd>
148 Return a list of frame records for the caller's stack. The first
149 entry in the returned list represents the caller; the last entry
150 represents the outermost call on the stack.
151</dl>
152
153<P>
154<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
155 <td><nobr><b><tt id='l2h-603' xml:id='l2h-603' class="function">trace</tt></b>(</nobr></td>
156 <td><var></var><big>[</big><var>context</var><big>]</big><var></var>)</td></tr></table></dt>
157<dd>
158 Return a list of frame records for the stack between the current
159 frame and the frame in which an exception currently being handled
160 was raised in. The first entry in the list represents the caller;
161 the last entry represents where the exception was raised.
162</dl>
163
164<DIV CLASS="navigation">
165<div class='online-navigation'>
166<p></p><hr />
167<table align="center" width="100%" cellpadding="0" cellspacing="2">
168<tr>
169<td class='online-navigation'><a rel="prev" title="3.11.3 Classes and functions"
170 href="inspect-classes-functions.html"><img src='../icons/previous.png'
171 border='0' height='32' alt='Previous Page' width='32' /></A></td>
172<td class='online-navigation'><a rel="parent" title="3.11 inspect "
173 href="module-inspect.html"><img src='../icons/up.png'
174 border='0' height='32' alt='Up One Level' width='32' /></A></td>
175<td class='online-navigation'><a rel="next" title="3.12 traceback "
176 href="module-traceback.html"><img src='../icons/next.png'
177 border='0' height='32' alt='Next Page' width='32' /></A></td>
178<td align="center" width="100%">Python Library Reference</td>
179<td class='online-navigation'><a rel="contents" title="Table of Contents"
180 href="contents.html"><img src='../icons/contents.png'
181 border='0' height='32' alt='Contents' width='32' /></A></td>
182<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
183 border='0' height='32' alt='Module Index' width='32' /></a></td>
184<td class='online-navigation'><a rel="index" title="Index"
185 href="genindex.html"><img src='../icons/index.png'
186 border='0' height='32' alt='Index' width='32' /></A></td>
187</tr></table>
188<div class='online-navigation'>
189<b class="navlabel">Previous:</b>
190<a class="sectref" rel="prev" href="inspect-classes-functions.html">3.11.3 Classes and functions</A>
191<b class="navlabel">Up:</b>
192<a class="sectref" rel="parent" href="module-inspect.html">3.11 inspect </A>
193<b class="navlabel">Next:</b>
194<a class="sectref" rel="next" href="module-traceback.html">3.12 traceback </A>
195</div>
196</div>
197<hr />
198<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
199</DIV>
200<!--End of Navigation Panel-->
201<ADDRESS>
202See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
203</ADDRESS>
204</BODY>
205</HTML>