@@ -470,23 +470,15 @@ \section{Thread State and the Global Interpreter Lock
470470for 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}
728720Release any resources previously acquired. After this call, Python's
729721state 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
733725Every call to \cfunction {PyGILState_Ensure()} must be matched by a call to
734726\cfunction {PyGILState_Release()} on the same thread.
0 commit comments