mirror of
https://github.com/python/cpython.git
synced 2025-11-08 21:52:45 +00:00
Replace example with simpler alternative using PyGILState_{Ensure,Require). Can someone please confirm this change is OK?
This commit is contained in:
parent
371d98ab15
commit
ff8113f8d0
1 changed files with 5 additions and 13 deletions
|
|
@ -470,23 +470,15 @@ Assuming you have access to an interpreter object, the typical idiom
|
||||||
for calling into Python from a C thread is
|
for calling into Python from a C thread is
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
PyThreadState *tstate;
|
PyGILState_STATE gstate;
|
||||||
PyObject *result;
|
gstate = PyGILState_Ensure();
|
||||||
|
|
||||||
/* interp is your reference to an interpreter object. */
|
|
||||||
tstate = PyThreadState_New(interp);
|
|
||||||
PyEval_AcquireThread(tstate);
|
|
||||||
|
|
||||||
/* Perform Python actions here. */
|
/* Perform Python actions here. */
|
||||||
result = CallSomeFunction();
|
result = CallSomeFunction();
|
||||||
/* evaluate result */
|
/* evaluate result */
|
||||||
|
|
||||||
/* Release the thread. No Python API allowed beyond this point. */
|
/* Release the thread. No Python API allowed beyond this point. */
|
||||||
PyEval_ReleaseThread(tstate);
|
PyGILState_Release(gstate);
|
||||||
|
|
||||||
/* You can either delete the thread state, or save it
|
|
||||||
until you need it the next time. */
|
|
||||||
PyThreadState_Delete(tstate);
|
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
\begin{ctypedesc}{PyInterpreterState}
|
\begin{ctypedesc}{PyInterpreterState}
|
||||||
|
|
@ -727,8 +719,8 @@ Failure is a fatal error.
|
||||||
\begin{cfuncdesc}{void}{PyGILState_Release}{PyGILState_STATE}
|
\begin{cfuncdesc}{void}{PyGILState_Release}{PyGILState_STATE}
|
||||||
Release any resources previously acquired. After this call, Python's
|
Release any resources previously acquired. After this call, Python's
|
||||||
state will be the same as it was prior to the corresponding
|
state will be the same as it was prior to the corresponding
|
||||||
\cfunction{PyGILState_Ensure} call (but generally this state will be unknown to
|
\cfunction{PyGILState_Ensure} call (but generally this state will be
|
||||||
the caller, hence the use of the GILState API.)
|
unknown to the caller, hence the use of the GILState API.)
|
||||||
|
|
||||||
Every call to \cfunction{PyGILState_Ensure()} must be matched by a call to
|
Every call to \cfunction{PyGILState_Ensure()} must be matched by a call to
|
||||||
\cfunction{PyGILState_Release()} on the same thread.
|
\cfunction{PyGILState_Release()} on the same thread.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue