[Pyrex] Callbacks from threads and PyGILState_Ensure/PyGILState_Release

Ulisses Furquim ulisses.silva at openbossa.org
Wed Aug 15 00:13:27 CEST 2007


Hi,

On 8/14/07, Ulisses Furquim <ulisses.silva at openbossa.org> wrote:
> Is there any way to tell pyrex that my call  to PyGILState_Release
> needs to be the last thing executed inside my function (before
> returning, of course)?

I couldn't find a _good_ way of doing this. I had the option to create
another wrapper for my callbacks just to surround the callback with
calls to PyGILState_Ensure and PyGILState_Release but that is really
bad as I have lots of callbacks. Then I thought it would be good to
have support in Pyrex for this and I wrote the attached patch for
Pyrex-0.9.5.1a.

The patch adds a reserved word '__grabgil' that can be added to cdef
functions to automatically generate calls to PyGILState_Ensure and
PyGILState_Release at the right places. One can use it like this:

cdef int my_callback(void *arg) __gragil:
    # the callback code calling a python function goes here
    pass

In this first version of the patch '__grabgil' must be the last token
before ':' but that can be easily changed. So.. what do you think? Is
that something you'd like to have in Pyrex? (I think it'd be good) If
you think so I'd be very happy to listen your suggestions/comments to
make it a mergeable patch.

Best regards,

-- Ulisses
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyrex-grabgil.patch
Type: text/x-patch
Size: 4871 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20070815/0bbf5171/attachment.bin 


More information about the Pyrex mailing list