Message116720
> 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);
} |
|
Date |
User |
Action |
Args |
2010-09-17 20:49:25 | amaury.forgeotdarc | set | recipients:
+ amaury.forgeotdarc, ncoghlan, nikratio, verigak, swapnil, anacrolix, docs@python |
2010-09-17 20:49:25 | amaury.forgeotdarc | set | messageid: <1284756565.71.0.0674315477993.issue6627@psf.upfronthosting.co.za> |
2010-09-17 20:49:23 | amaury.forgeotdarc | link | issue6627 messages |
2010-09-17 20:49:23 | amaury.forgeotdarc | create | |
|