extension module, thread safety?

Nick Coghlan ncoghlan at iinet.net.au
Tue Jan 18 03:52:38 EST 2005

Pierre Barbier de Reuille wrote:
> With the current CPython, it's very hard to mix Python and C in a 
> multithreading application (with C-threads, not Python-threads). In fact 
> I never really succeeded in that task because of that GIL ! I have a 
> multi-thread application but every bit of Python code must be run into a 
> Python thread. To be more precise, I wanted to be able to call Python 
> code in response to some GUI events, and I didn't want to instanciate a 
> new interpreter for I wanted to be able to access the environment of my 
> main Python interpreter.

I don't understand. This is what PyGILState_Ensure and PyGILState_Release are 
for - so C code can leave the GIL unlocked by default, and only grab it when 
they want to call into the C/Python API.


Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia

More information about the Python-list mailing list