[Pyrex] Callbacks from threads and PyGILState_Ensure/PyGILState_Release

Stefan Behnel stefan_ml at behnel.de
Thu Sep 13 09:56:26 CEST 2007


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.


> 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.

Stefan




More information about the Pyrex mailing list