[Cython] 'with gil:' statement

Stefan Behnel stefan_ml at behnel.de
Wed Mar 16 15:11:16 CET 2011

Dag Sverre Seljebotn, 16.03.2011 11:58:
> On 03/16/2011 11:28 AM, mark florisson wrote:
>> I implemented the 'with gil:' statement, and have added error checking
>> for nested 'with gil' or 'with nogil' statements. For instance, with
>> the patch applied Cython wil issue an error when you have e.g.
>> with nogil:
>>     with nogil:
>>         ...
>> (or the same thing for 'with gil:'). This because nested 'nogil' or
>> 'gil' blocks, without intermediate GIL-acquiring/releasing, will abort
>> the Python interpreter. However, if people are acquiring the GIL
>> manually in nogil blocks and then want to release the GIL with a
>> 'nogil' block, it will incorrectly issue an error. I do think this
>> kind of code is uncommon, but perhaps we want to issue a warning
>> instead?
> I think we should make nested nogil-s noops, i.e.
> with nogil:
>     with nogil: # => if True:

-1, the compiler should bark at clearly nonsensical code. The above, if 
encountered in the wild, is most likely a copy&paste bug that wasn't 
intended that way. (ok, you'd most likely get other errors as well due to 
GIL checking, but that doesn't change the fact that the code is nonsensical)


More information about the cython-devel mailing list