File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -466,6 +466,28 @@ \section{Thread State and the Global Interpreter Lock
466466this must be done by a thread that is created by Python or by the main
467467thread after Python is initialized).
468468
469+ Assuming you have access to an interpreter object, the typical idiom
470+ for calling into Python from a C thread is
471+
472+ \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);
479+
480+ /* Perform Python actions here. */
481+ result = CallSomeFunction();
482+ /* evaluate result */
483+
484+ /* 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);
490+ \end {verbatim }
469491
470492\begin {ctypedesc }{PyInterpreterState}
471493 This data structure represents the state shared by a number of
You can’t perform that action at this time.
0 commit comments