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

Stefan Behnel stefan_ml at behnel.de
Mon Sep 17 09:54:34 CEST 2007


Ulisses Furquim wrote:
>     cdef void my_callback(void *data):
>       with GIL:
>         print "Called back!"
> 
>     def heavy():
>       without GIL:
>          do_something_heavy(my_callback)

The two constructs are not symmetric. You'd normally release the GIL around a
code block (possibly, but not necessarily involving a function call), and
re-acquire the GIL for the execution of a (callback-)function.

Thus a "without GIL" block and a "with GIL" function annotation matches well
with common use patterns *and* with the code that Pyrex commonly generates.

Stefan



More information about the Pyrex mailing list