diff options
author | Andrew M. Kuchling <amk@amk.ca> | 2004-07-10 13:42:52 (GMT) |
---|---|---|
committer | Andrew M. Kuchling <amk@amk.ca> | 2004-07-10 13:42:52 (GMT) |
commit | ff8113f8d02dc14f10b99d2e71f17c1a5fd24d52 (patch) | |
tree | ffc93d759e3c9b353af3e7e88bdf66a4817aa1ce /Doc/api/init.tex | |
parent | 371d98ab15a8911b1682d49727f1faf3c4849127 (diff) | |
download | cpython-ff8113f8d02dc14f10b99d2e71f17c1a5fd24d52.zip cpython-ff8113f8d02dc14f10b99d2e71f17c1a5fd24d52.tar.gz cpython-ff8113f8d02dc14f10b99d2e71f17c1a5fd24d52.tar.bz2 |
Replace example with simpler alternative using PyGILState_{Ensure,Require). Can someone please confirm this change is OK?
Diffstat (limited to 'Doc/api/init.tex')
-rw-r--r-- | Doc/api/init.tex | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/Doc/api/init.tex b/Doc/api/init.tex index f34e0f0..56d9039 100644 --- a/Doc/api/init.tex +++ b/Doc/api/init.tex @@ -470,23 +470,15 @@ 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); + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); /* 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); + PyGILState_Release(gstate); \end{verbatim} \begin{ctypedesc}{PyInterpreterState} @@ -727,8 +719,8 @@ Failure is a fatal error. \begin{cfuncdesc}{void}{PyGILState_Release}{PyGILState_STATE} Release any resources previously acquired. After this call, Python's state will be the same as it was prior to the corresponding -\cfunction{PyGILState_Ensure} call (but generally this state will be unknown to -the caller, hence the use of the GILState API.) +\cfunction{PyGILState_Ensure} call (but generally this state will be +unknown to the caller, hence the use of the GILState API.) Every call to \cfunction{PyGILState_Ensure()} must be matched by a call to \cfunction{PyGILState_Release()} on the same thread. |