[docs] [issue6627] threading.local() does not work with C-created threads

Amaury Forgeot d'Arc report at bugs.python.org
Fri Sep 17 22:49:25 CEST 2010

Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:

> ctypes performs the initializations in a way that break the
> threading.local functionality. 

Not quite. ctypes (or more exactly: the PyGILState_Ensure() and PyGILState_Release() functions, which are the standard API to do this) is in a situation where it must call Python code from a thread which has no PyThreadState.  So it creates a thread state, runs the code, and destroys the thread state; is this wrong?

If you want to keep Python state during your C thread, there are 4 lines to add to your function:

void *async_cb(void *dummy)
    PyGILState_STATE gstate = PyGILState_Ensure();

resolution:  -> works for me
status: open -> closed

Python tracker <report at bugs.python.org>

More information about the docs mailing list