Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff8113f

Browse files
committed
Replace example with simpler alternative using PyGILState_{Ensure,Require). Can someone please confirm this change is OK?
1 parent 371d98a commit ff8113f

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

Doc/api/init.tex

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -470,23 +470,15 @@ \section{Thread State and the Global Interpreter Lock
470470
for calling into Python from a C thread is
471471

472472
\begin{verbatim}
473-
PyThreadState *tstate;
474-
PyObject *result;
475-
476-
/* interp is your reference to an interpreter object. */
477-
tstate = PyThreadState_New(interp);
478-
PyEval_AcquireThread(tstate);
473+
PyGILState_STATE gstate;
474+
gstate = PyGILState_Ensure();
479475
480476
/* Perform Python actions here. */
481477
result = CallSomeFunction();
482478
/* evaluate result */
483479
484480
/* Release the thread. No Python API allowed beyond this point. */
485-
PyEval_ReleaseThread(tstate);
486-
487-
/* You can either delete the thread state, or save it
488-
until you need it the next time. */
489-
PyThreadState_Delete(tstate);
481+
PyGILState_Release(gstate);
490482
\end{verbatim}
491483

492484
\begin{ctypedesc}{PyInterpreterState}
@@ -727,8 +719,8 @@ \section{Thread State and the Global Interpreter Lock
727719
\begin{cfuncdesc}{void}{PyGILState_Release}{PyGILState_STATE}
728720
Release any resources previously acquired. After this call, Python's
729721
state will be the same as it was prior to the corresponding
730-
\cfunction{PyGILState_Ensure} call (but generally this state will be unknown to
731-
the caller, hence the use of the GILState API.)
722+
\cfunction{PyGILState_Ensure} call (but generally this state will be
723+
unknown to the caller, hence the use of the GILState API.)
732724

733725
Every call to \cfunction{PyGILState_Ensure()} must be matched by a call to
734726
\cfunction{PyGILState_Release()} on the same thread.

0 commit comments

Comments
 (0)