18 Oct
2010
18 Oct
'10
6:55 a.m.
On 18/10/2010 1:00 PM, Nikolaus Rath wrote:
Hello,
I am starting threads in a C extension. If I understand correctly, successive sequences of PyGILState_Ensure() and PyGILState_Release will create and destroy the Python thread state over and over again, so e.g. objects stored with threading.Local() will not persist.
Can someone explain to me how I can initialize and destroy the thread state manually (i.e., right after creating and destroying the thread with pthreads), so that PyGILState_* will just acquire and release the GIL?
You can just Ensure as your thread starts and the Release as it terminates. You can then use the normal Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS macros to release the GIL as appropriate.
HTH,
Mark