[Pyrex] [Cython-dev] Callbacks from threads and PyGILState_Ensure/PyGILState_Release

Ulisses Furquim ulisses.silva at openbossa.org
Thu Sep 13 20:06:38 CEST 2007


Hi,

On 9/13/07, Robert Bradshaw <robertwb at math.washington.edu> wrote:
> 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.

I don't think we should bother with this situation. One as a
programmer already have to do that for other things such as seeing if
you can call a function without holding a lock or not. It's something
programmers have to do.

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

Yes, one could do that but it's a pretty special case, nevertheless.
And if you want to do that, if you want to pass a method as callback
you should pay attention in which context it's gonna be executed and
use "with GIL" if necessary.

I really think we should stick to Python's mantra and "keep it
simple". After all, it's pretty much an implementation issue as Stefan
already said.

Regards,

-- Ulisses



More information about the Pyrex mailing list