[Pyrex] pyrex and GIL

Simon Burton simon at arrowtheory.com
Thu Feb 19 05:47:12 CET 2004


>On Feb 18, 2004, at 6:14 PM, Simon Burton wrote:
>
>>> Just out of curiosity, how does one acquire the GIL (Python/C API)?
>>>
>>
>> From sec 8.1 of the python/C api ref:
>> http://www.python.org/doc/2.3/api/threads.html
>>
>> Assuming you have access to an interpreter object, the typical idiom 
>> for
>> calling into Python from a C thread is
>
>I don't know it off the top of my head, but I'm pretty sure there is a 
>different Python 2.3 API for doing this that does not assume you have a 
>reference to an interpreter object (which is the common case).
>
>-bob
>
>

Yes, that would be PEP 311, which was implemented in python 2.3:


    Common usage will be:

    void SomeCFunction(void)
    {
        /* ensure we hold the lock */
        PyGILState_STATE state = PyGILState_Ensure();
        /* Use the Python API */
        ...
        /* Restore the state of Python */
        PyGILState_Release(state);
    }


Simon.




More information about the Pyrex mailing list