Multithreaded C API Python questions

Farshid Lashkari no at
Thu Nov 9 18:32:17 CET 2006

Svein Seldal wrote:
> I'm unable to get access to python as long as another python call is 
> executing. The PyEval_AcquireThread() call blocks until the first call 
> returns. I was hoping that the python system itself would release the 
> GIL after some execution, but it itsnt.
> I am dependent upon the ability to have to threads executing in python 
> land at the same time. How can this be done?

Are you creating your threads through python or through C code? If you 
are only creating it through C code, then make sure you initialize the 
GIL with the following call at the beginning of your application:


 From my experience, calling PyGILState_Ensure() was enough. I didn't 
need to call any extra threading functions. But make sure that every 
call to PyGILState_Ensure() is matched with a call to PyGILState_Release()


More information about the Python-list mailing list