Amaury Forgeot d'Arc <amaur...@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();
    Py_BEGIN_ALLOW_THREADS
    (*callback_fn)();
    (*callback_fn)();
    Py_END_ALLOW_THREADS
    PyGILState_Release(gstate);
    pthread_exit(NULL);
}

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

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6627>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to