summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-03-02 13:17:20 (GMT)
committerGuido van Rossum <guido@python.org>2003-03-02 13:17:20 (GMT)
commit41bcbe3050564caf69ad5ef2438e1f65ddb02df6 (patch)
treed9444ebd8f4a658867eee43f38d61a0400dc4a03
parentfc27375d5a5db8976c37c181554e55e19840a75b (diff)
downloadcpython-41bcbe3050564caf69ad5ef2438e1f65ddb02df6.zip
cpython-41bcbe3050564caf69ad5ef2438e1f65ddb02df6.tar.gz
cpython-41bcbe3050564caf69ad5ef2438e1f65ddb02df6.tar.bz2
Commit MvL's doc patch for SF bug #221327. This adds an example of
calling into Python from a C thread.
-rw-r--r--Doc/api/init.tex22
1 files changed, 22 insertions, 0 deletions
diff --git a/Doc/api/init.tex b/Doc/api/init.tex
index 663c2fe..f0ca287 100644
--- a/Doc/api/init.tex
+++ b/Doc/api/init.tex
@@ -466,6 +466,28 @@ you must obtain the thread state and access its \member{interp} member;
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 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}
This data structure represents the state shared by a number of