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

Ulisses Furquim ulisses.silva at openbossa.org
Fri Sep 21 21:13:32 CEST 2007


Hi,

On 9/18/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> A middle ground would be to provide another annotation
> somehow to tell Pyrex to acquire the GIL, such as
>
>    cdef void myfunc() acquires GIL:
>      ...

This is what is integrated in Cython repository now. The patch there
is using 'with GIL' instead of 'acquires GIL', though.

> Another way would be to write
>
>    cdef void myfunc() nogil:
>      with GIL:
>        ...
>
> and have Pyrex recognise 'with GIL' at the top level of
> the body as a special case and generate GIL-acquiring code
> around everything. I'm leaning towards this, because it
> would avoid introducing a notation that would become
> obsolete later with a smarter implementation.

Ok, I'd given it a try and a first version of this patch is attached
(for Pyrex 0.9.5.1a). It implements only this special case to
recognise 'with GIL' at the top level of the body and generate the
GIL-acquiring and releasing code. It supports a list of comma
separated identifiers after 'with' (exactly like the patch for Cython)
if we ever want to extend this to other "contexts".

So, what do we do now? Cython has one patch in their repository but I
don't know if we've reached a consensus (or if we need one at all)?
The two patches have the same functionality but different notations.
Maybe this new patch is more clear that we're messing with the
function's implementation and not its signature? I must say it's
certainly more clear to me with this new notation.

Best regards,

-- Ulisses
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyrex-with-block.patch
Type: text/x-patch
Size: 6346 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20070921/ccccde22/attachment.bin 


More information about the Pyrex mailing list