[Python-checkins] python/dist/src/Doc/api init.tex,1.6,1.7

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Sun, 02 Mar 2003 05:17:22 -0800


Update of /cvsroot/python/python/dist/src/Doc/api
In directory sc8-pr-cvs1:/tmp/cvs-serv11849

Modified Files:
	init.tex 
Log Message:
Commit MvL's doc patch for SF bug #221327.  This adds an example of
calling into Python from a C thread.


Index: init.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/api/init.tex,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** init.tex	10 Feb 2003 19:12:42 -0000	1.6
--- init.tex	2 Mar 2003 13:17:20 -0000	1.7
***************
*** 467,470 ****
--- 467,492 ----
  thread after Python is initialized).
  
+ Assuming you have access to an interpreter 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}