[Python-Dev] PEP-311 operational?
Todd Miller
jmiller@stsci.edu
12 Jun 2003 17:49:33 -0400
I've been trying for a day or so to use the new PyGILState_Ensure() and
PyGILState_Release() calls. I started with a Python multi-threaded test
case and a simple hypothetical extension function. I want to protect
the extension function in case it gets called from an embedded context
by a non-Python thread. (In truth, I started with numarray stuff where
this makes slightly more sense; I wanted to protect an API function.)
It is now my impression that an extension function with the following
core contents:
{ PyGILState_STATE state = PyGILState_Ensure();
int i;
for(i=0; i<100000; i++);
PyGILState_Release(state);
}
will deadlock (in the Ensure), provided it is called from some secondary
thread from Python. I thought this would be OK and that the
Ensure/Release would essentially be a noop. Did I misread the PEP? Is
the PEP-311 code finished yet?
(I tried this under Red Hat 8 and Windows 2000 pro with Python CVS)
Thanks,
Todd