[Pyrex] [Cython-dev] Callbacks from threads and PyGILState_Ensure/PyGILState_Release
Robert Bradshaw
robertwb at math.washington.edu
Fri Sep 14 21:22:22 CEST 2007
On Sep 13, 2007, at 11:21 PM, Stefan Behnel wrote:
> Greg Ewing wrote:
>> Stefan Behnel wrote:
>>> Robert Bradshaw wrote:
>>>
>>>> 1) Between pyx and pxd files. If we allow them to differ, which
>>>> takes
>>>> precedence?
>>
>> They would have to be "sufficiently compatible". If the
>> pxd does not annotate, and the pyx annotates as "without
>> GIL", that's acceptable, but not the other way around.
>>
>> However, I'm not sure there would be any benefit in
>> allowing this flexibility, so I would probably just
>> require them to match, at least in a first implementation.
>
> Hmmm, have you actually read my post that you stripped from the
> quote above?
>
> I was proposing the exact opposite: disallow "with GIL" in .pxd
> files and in
> function pre-declarations, and only allow them on the function
> implementation.
> That way, you have them where they are required (and where they
> make sense)
> and you just can't get it wrong because it's declared at the point
> closest to
> the code that requires (or does not require) the GIL.
>
> The reasoning is that you are not gaining anything by declaring a
> function
> signature "with GIL". It might get called from Python code, it
> might get
> called from Cython/Pyrex code holding or not holding the GIL, and
> it might get
> called from third party code as a callback. There is no way Pyrex/
> Cython can
> always make sure it knows if the GIL is held by the calling code.
> It's C after
> all, things can get called from all over the place. So Pyrex/Cython
> should not
> rely on its knowledge about the code it sees and just acquire the
> GIL inside
> the implementation. Which makes it a clear implementation detail
> that is in no
> way interesting to the outside world. It's not a signature issue.
I think the "without GIL" idea that Greg is proposing is potentially
more powerful, probably more subtle, and certainly further from
implementation that the "with GIL" statement as already implemented.
I propose we disallow this decelerator in pxd files/forward
declaration for this case.
- Robert
More information about the Pyrex
mailing list