extension module, thread safety?

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Tue Jan 18 04:01:02 EST 2005

Nick Coghlan a écrit :
> 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.
> Regards,
> Nick.

Ok, I wondered why I didn't know these functions, but they are new to 
Python 2.4 ( and I didn't take the time to look closely at Python 2.4 as 
some modules I'm working with are still not available for Python 2.4). 
But if it really allows to call Python code outside a Python thread ... 
then I'll surely use that as soon as I can use Python 2.4 :) Thanks for 
the hint :)


More information about the Python-list mailing list