📄 265.html
字号:
<pre>
void PyEval_ReleaseThread(PyThreadState *tstate)
</pre>
<p>Resets the current thread state to <tt class="monofont">NULL</tt> and releases the global interpreter lock. The lock must have been created earlier and must be held by the current thread. The <Tt cLass="monofont">tstate</Tt> argument, which must not be <tt cLass="monofont">NULL,</TT> is only used to check that it represents the current thread state梚f it isn't, a fatal error is reported. This function is not available when thread support is disabled at compile time.</P>
<Pre>
PyThreadState* PyEval_SaveThread()
</prE>
<P>Releases the interpreter lock (if it has been created and thread support is enabled) and resets the thread state to <TT clasS="monofont">NULL,</TT> returning the previous thread state (which is not <Tt claSS="monofont">NULL</TT>). If the lock has been created, the current thread must have acquired it. (This function is available even when thread support is disabled at compile time.)</p>
<pre>
void PyEval_RestoreThread(PyThreadState *tstate)
</pre>
<p>Acquires the interpreter lock (if it has been created and thread support is enabled) and sets the thread state to <tt class="monofont">tstate,</tt> which must not be <tt cLasS="monofont">NULL.</tt> If the lock has been created, the current thread must not have acquired it, otherwise deadlock ensues. (This function is available even when thread support is disabled at compile time.)</p>
<P>The following macros are normally used without a trailing semicolon; look for example usage in the Python source distribution.</p>
<pre>
Py_BEGIN_ALLOW_THREADS
</Pre>
<p>This macro expands to <TT CLass="monofont">"{ PyThreadState *_save; _save = PyEval_SaveThread();".</tT> Note that it contains an opening brace; it must be matched with the following <TT Class="monofont">Py_END_ALLOW_THREADS</TT> macro. It is a no-op when thread support is disabled at compile time.</P>
<Pre>
Py_END_ALLOW_THREADS
</prE>
<P>This macro expands to <TT class="monofont">"PyEval_RestoreThread(_save); } ".</tt> Note that it contains a closing brace; it must be matched with an earlier <tt class="monofont">Py_BEGIN_ALLOW_THREADS</tt> macro. See earlier section for further discussion of this macro. It is a no-op when thread support is disabled at compile time.</p>
<pre>
Py_BEGIN_BLOCK_THREADS
</Pre>
<P>This macro expands to <tt cLass="monofont">"PyEval_RestoreThread(_save);"</tT> that is, it is equivalent to <tt cLASS="monofont">Py_END_ALLOW_THREADS</tt> without the closing brace. It is a no-op when thread support is disabled at compile time.</p>
<pRE>
Py_BEGIN_UNBLOCK_THREADS
</PRe>
<p>This macro expands to <tt CLASs="monofont">"_save = PyEval_SaveThread();"</tt> that is, it is equivalent to <tT CLAss="monofont">Py_BEGIN_ALLOW_THREADS</tt> without the opening brace and variable declaration. It is a no-op when thread support is disabled at compile time.</p>
<p>All the following functions are only available when thread support is enabled at compile time, and must be called only when the interpreter lock has been created.</p>
<pre>
PyInterpreterState* PyInterpreterState_New()
</pre>
<p>Creates a new interpreter state object. The interpreter lock need not be held, but can be held if it is necessary to serialize calls to this function.</p>
<blockQuoTe>
<p><p><Tt claSs="monofont">void PyInterpreterState_Clear(PyInterpreterState *interp)</tt>棤
Resets all information in an interpreter state object. The interpreter lock must be held.</P>
</P>
<P><P><tt clASS="monofont">void PyInterpreterState_Delete(PyInterpreterState *interp)</Tt>棤
Destroys an interpreter state object. The interpreter lock need not be held. The interpreter state must have been reset with a previous call to <tt cLASS="monofont">PyInterpreterState_Clear().</tt></p>
</p>
<P><P><TT class="monofont">PyThreadState* PyThreadState_New(PyInterpreterState *interp)</tt>棤
Creates a new thread state object belonging to the given interpreter object. The interpreter lock need not be held, but might be held if it is necessary to serialize calls to this function.</p>
</p>
<p><p><tt class="monofont">void PyThreadState_Clear(PyThreadState *tstate)</tt>棤
Resets all information in a thread state object. The interpreter lock must be held.</P>
</p>
<p><P><tt cLass="monofont">void PyThreadState_Delete(PyThreadState *tstate)</tT>棤
Destroys a thread state object. The interpreter lock need not be held. The thread state must have been reset with a previous call to <tt cLASS="monofont">PyThreadState_Clear().</tt></p>
</p>
<P><P><TT clasS="monofont">PyThreadState* PyThreadState_Get()</TT>棤
Returns the current thread state. The interpreter lock must be held. When the current thread state is <Tt claSS="monofont">NULL,</TT> this issues a fatal error (so that the caller needn't check for <tt class="monofont">NULL</tt>).</p>
</p>
<p><p><tt class="monofont">PyThreadState* PyThreadState_Swap(PyThreadState *tstate)</Tt>棤
Swaps the current thread state with the thread state given by the argument <tT claSs="monofont">tstate,</tt> which might be <tT claSS="monofont">NULL.</TT> The interpreter lock must be held.<a namE="idx1073751277"></A><A Name="idx1073751278"></a><A NAMe="idx1073751279"></a><a nAME="idx1073751280"></A><a name="idx1073751281"></a><a name="idx1073751282"></a><a name="idx1073751283"></a><a nAme="idx1073751284"></A><a naMe="idx1073751285"></a><a nAme="idx1073751286"></a><A NAMe="idx1073751287"></a><a nAME="idx1073751288"></A><a namE="idx1073751289"></A><A Name="idx1073751290"></a><A NAMe="idx1073751291"></a><a name="idx1073751292"></a>
</p>
</p>
</blockquote>
</FonT>
<P><TABLE width="100%" border=0><TR valign="top"><TD><font size=1 color="#C0C0C0"><br></font></TD><TD align=right><font size=1 color="#C0C0C0">Last updated on 1/30/2002<br>Python Developer's Handbook, © 2002 Sams Publishing</font></TD></TR></TABLE></P>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="264.html" title="Concrete Objects Layer"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=265" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="265.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="266.html" title="Memory Management"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
</TD></TR></TABLE>
<br><TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD><H4 class=Title>Index terms contained in this section</H4>
<font size=2>
Application Programmers Interface (API)<BR>
Python/C<BR>
<a href="#idx1073751240">initialization, finalization, and threads</a> <a href="#idx1073751247">2nd</a> <a href="#idx1073751256">3rd</a> <a href="#idx1073751278">4th</a><BR>
applications<BR>
multithreaded<BR>
<a href="#idx1073751268">support</a> <a href="#idx1073751290">2nd</a><BR>
<a href="#idx1073751262">char* Py_GetExecPrefix() function</a><BR>
<a href="#idx1073751264">const char* Py_GetVersion() function</a><BR>
creating<BR>
<a href="#idx1073751273">thread data structures</a><BR>
<a href="#idx1073751243">finalization, Python/C Application Programmers Interface (API)</a> <a href="#idx1073751250">2nd</a> <a href="#idx1073751259">3rd</a> <a href="#idx1073751281">4th</a><BR>
functions<BR>
<a href="#idx1073751263">char* Py_GetExecPrefix()</a><BR>
<a href="#idx1073751265">const char* Py_GetVersion()</a><BR>
<a href="#idx1073751245">initialization, finalization, and threads</a> <a href="#idx1073751252">2nd</a> <a href="#idx1073751261">3rd</a> <a href="#idx1073751283">4th</a><BR>
<a href="#idx1073751254">PyThreadState* Py_NewInterpreter()</a><BR>
<a href="#idx1073751272">sys.exec_info()</a><BR>
<a href="#idx1073751238">void Py_Finalize()</a><BR>
<a href="#idx1073751285">global locks, thread state</a><BR>
<a href="#idx1073751242">initialization, Python/C Application Programmers Interface (API)</a> <a href="#idx1073751249">2nd</a> <a href="#idx1073751258">3rd</a> <a href="#idx1073751280">4th</a><BR>
interfaces<BR>
Python/C Application Programmers (API)<BR>
<a href="#idx1073751241">initialization, finalization, and threads</a> <a href="#idx1073751248">2nd</a> <a href="#idx1073751257">3rd</a> <a href="#idx1073751279">4th</a><BR>
interpreters<BR>
<a href="#idx1073751287">global locks, thread state</a><BR>
locks<BR>
<a href="#idx1073751286">global interpreter, thread state</a><BR>
multithreaded programs<BR>
<a href="#idx1073751267">support</a> <a href="#idx1073751289">2nd</a><BR>
programs<BR>
multithreaded<BR>
<a href="#idx1073751269">support</a> <a href="#idx1073751291">2nd</a><BR>
Python/C Application Programmers Interface (API)<BR>
<a href="#idx1073751239">initialization, finalization, and threads</a> <a href="#idx1073751246">2nd</a> <a href="#idx1073751255">3rd</a> <a href="#idx1073751277">4th</a><BR>
<a href="#idx1073751253">PyThreadState* Py_NewInterpreter() function</a><BR>
software<BR>
multithreaded<BR>
<a href="#idx1073751270">support</a> <a href="#idx1073751292">2nd</a><BR>
state<BR>
<a href="#idx1073751284">threads, global locks</a><BR>
structures<BR>
<a href="#idx1073751275">thread data, creating</a><BR>
support<BR>
<a href="#idx1073751266">multithreaded programs</a> <a href="#idx1073751288">2nd</a><BR>
<a href="#idx1073751271">sys.exec_info() function</a><BR>
<a href="#idx1073751276">thread data structures, creating</a><BR>
threads<BR>
<a href="#idx1073751244">Python/C Application Programmers Interface (API)</a> <a href="#idx1073751251">2nd</a> <a href="#idx1073751260">3rd</a> <a href="#idx1073751282">4th</a><BR>
<a href="#idx1073751237">void Py_Finalize() function</a><BR>
writing<BR>
<a href="#idx1073751274">thread data structures</a><BR>
<BR>
</font></TD></TR></TABLE>
<!--EndOfBrowse-->
</TD></TR></TABLE>
<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#990000><tr><td><p align=center><font size=1 face="verdana,arial,helvetica" color=white>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -