[capi-sig] How to initialize state for C created threads
Mark Hammond
skippy.hammond at gmail.com
Mon Oct 18 05:55:07 CEST 2010
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
More information about the capi-sig
mailing list