[Pyrex] Callbacks from threads and PyGILState_Ensure/PyGILState_Release
Robert Bradshaw
robertwb at math.washington.edu
Thu Sep 13 11:05:03 CEST 2007
On Sep 13, 2007, at 12:56 AM, Stefan Behnel wrote:
> Robert Bradshaw wrote:
>> Back to the question of whether or not signatures match, I see
>> only two
>> instance where we care about types matching.
>>
>> 1) Between pyx and pxd files. If we allow them to differ, which takes
>> precedence? It only benefits the lazy to allow mismatch here.
>
> I don't think so. As I already said, we are not talking about
> interfaces here,
> only about implementation details. If I define a function in a .pxd
> file
> without annotating it with "with GIL", but then I implement such a
> function
> and say that I want it to execute "with GIL", that can be perfectly
> reasonable. I don't see much sense in the opposite, but maybe I'm
> just missing
> something.
>
> How about disallowing "with GIL" in .pxd files and in function
> pre-declarations? That way, we avoid the problem all together.
You have a good point that it is an implementation rather than
signature issue, and if we take this approach then disallowing "with
GIL" in pxd files/function pre-declarations should be done. The only
drawback I see is that as a programmer (and/or more intelligent
future version of pyrex) I have to look in the pyx file (not just the
pxd file) to decide if its safe to call if I don't currently have the
GIL. This latter situation is purely hypothetical and may not be
worth bothering with.
>> 2) When subclassing cdef classes and overriding cdef functions. In
>> this
>> case, if one wants to use the function as a callback, it always
>> requires
>> the GIL (due to the self parameter) and will probably save a lot of
>> mistakes to throw an error when they don't match.
>
> How would you use a method as a callback? That would require
> passing self
> already in some way, right? So you can only do that from Python/
> Pyrex code
> anyway, which makes the problem a pretty special case.
If the callback was of the form
foo(void *, ...)
and the void * was user-specified, one could do that.
More information about the Pyrex
mailing list