[Pyrex] Pyrex and the GIL

Bob Ippolito bob at redivi.com
Tue Sep 13 04:41:51 CEST 2005


On Sep 12, 2005, at 7:22 PM, Greg Ewing wrote:

> Andrew Bennetts wrote:
>
>
>> Anyone wanting to write callbacks to pass to C functions is surely  
>> going to
>> need this, if by "don't care" you mean "needs GIL, and will  
>> acquire it if
>> necessary."
>>
>
> No, it simply means that, to calling code, it doesn't matter
> whether the GIL is held or not when the call is made.
>
> If the function is written in Pyrex and uses Python opeations,
> then clearly it does need the GIL, so the compiler must
> insert code to acquire it. Probably this will be done using
> PyThreadState_Ensure, so the exact semantics will be "don't
> care". Interpreting it from the outside as "requires GIL
> released" is stricter than necessary, but not harmful.
>
>
>> Hmm, I think ensures_gil sounds like part of the signature myself  
>> -- it's
>> declaring something about the state of the world that the function  
>> expects
>>
>
> But it could also be taken to imply that it does actually
> acquire the GIL if it's not already held, which is a property
> of the implementation.

Well, CPython is the only implementation that matters, and  
PyGILState_Ensure has *exactly* that implication

-bob




More information about the Pyrex mailing list