[Pyrex] Pyrex and the GIL

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Sep 12 11:20:54 CEST 2005


Bob Ippolito wrote:

> Perhaps there should be a "try:finally:" style construct for doing  some 
> chunk of code without the GIL?  That seems to make a lot more  sense 
> than trying to do it at function boundaries.

The nice thing about doing it at function boundaries is
that it's easy to make sure the right thing is done.
Without safeguards, a nogil-block statement would be
quite error-prone, seeing as Pyrex makes it so easy to
invoke Python operations while hardly realising it.

Enforcing the necessary safeguards would require the
Pyrex compiler to track the GIL state at all points in
the code and meticulously check whether each Python
operation is allowable. And you'd *still* need GIL
information in the function signatures, so that calls
can be checked for permissibility.

So as I see it, adding GIL declarations to function
headers is a necessary first step. A nogil-block statement
could perhaps be added later, if desired.

Greg



More information about the Pyrex mailing list