Releasing GIL in unknown state
Farshid Lashkari
no at spam.com
Wed Aug 30 00:39:29 EDT 2006
Hi,
Is there a proper way for C code to ensure that the GIL is released? I
know about PyGILState_Ensure and PyGILState_Release, but that is to
ensure the GIL is acquired. I have some extension code that does heavy
processing and I want to release the GIL, but the code can't be sure
that the GIL is already acquired. All I can think of so far is the
following:
PyGILState_STATE state = PyGILState_Ensure();
Py_BEGIN_ALLOW_THREADS
//do processing
Py_END_ALLOW_THREADS
PyGILState_Release(state)
Is there a better way?
-Farshid
More information about the Python-list
mailing list