This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author glchapman21
Recipients glchapman21, kunoospald, urBan_dK
Date 2007-11-18.17:58:04
SpamBayes Score 0.05452327
Marked as misclassified No
Message-id <1195408684.75.0.0420859511841.issue1720250@psf.upfronthosting.co.za>
In-reply-to
Content
In my embedding, I use the following (adapting the example above):

// initialize the Python interpreter
Py_Initialize();

PyEval_InitThreads();

/* Swap out and return current thread state and release the GIL */
PyThreadState tstate = PyEval_SaveThread();

PyGILState_STATE gstate;
gstate = PyGILState_Ensure();

PyRun_SimpleString("import random\n");

PyGILState_Release(gstate); 


You don't have to free the tstate returned by PyEval_SaveThread because
it is the thread state of the main thread (as established during
Py_Initialize), and so it will be freed during Python's shut-down.

I think in general you should rarely need to call PyEval_ReleaseLock
directly; instead use PyEval_SaveThread, the Py_BEGIN_ALLOW_THREADS
macro, or PyGILState_Release (as appropriate).  The documentation should
probably say as much.
History
Date User Action Args
2007-11-18 17:58:05glchapman21setspambayes_score: 0.0545233 -> 0.05452327
recipients: + glchapman21, kunoospald, urBan_dK
2007-11-18 17:58:04glchapman21setspambayes_score: 0.0545233 -> 0.0545233
messageid: <1195408684.75.0.0420859511841.issue1720250@psf.upfronthosting.co.za>
2007-11-18 17:58:04glchapman21linkissue1720250 messages
2007-11-18 17:58:04glchapman21create