Index: init.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/api/init.tex,v retrieving revision 1.3 diff -u -r1.3 init.tex --- init.tex 9 Apr 2002 21:09:42 -0000 1.3 +++ init.tex 4 Aug 2002 09:46:02 -0000 @@ -466,6 +466,28 @@ this must be done by a thread that is created by Python or by the main thread after Python is initialized). +Assuming you have access to an interpeter object, the typical idiom +for calling into Python from a C thread is + +\begin{verbatim} + PyThreadState *tstate; + PyObject *result; + + /* interp is your reference to an interpreter object. */ + tstate = PyThreadState_New(interp); + PyEval_AcquireThread(tstate); + + /* Perform Python actions here. */ + result = CallSomeFunction(); + /* evaluate result */ + + /* Release the thread. No Python API allowed beyond this point. */ + PyEval_ReleaseThread(tstate); + + /* You can either delete the thread state, or save it + until you need it the next time. */ + PyThreadState_Delete(tstate); +\end{verbatim} \begin{ctypedesc}{PyInterpreterState} This data structure represents the state shared by a number of