On Tue, Apr 14, 2015 at 6:13 AM, Thouis (Ray) Jones <
tho...@gmail.com> wrote:
> In the code below, the c_sqrt_safe() function grabs the GIL at the end of
> the function, even if there was no exception raised. This seems
> unnecessary, unless I'm misunderstanding something about nogil functions
> that contain raise statements.
It's not so much about the "raise" as it is about the with-gil block.
If a function contains such a block, some cleanup is assumed to be
required at exit. In particular, consider
cdef double c_sqrt(int value) nogil:
if value % 2:
with gil:
py_var1 = object()
if value % 3:
with gil:
py_var2 = object()
return sqrt(value)
in this case, one or both py_var1 or py_var2 may need to be decref'd
at the return of the function. Conceivably one could try to be more
intelligent and only generate the gil-capturing if it's needed (both
in this case and the exception raising case).
> If this behavior is actually necessary, it would be nice for Cython to warn
> when a nogil function might implicitly grab the gil.
The "with gil" is the indication that this function will implicitly
grab the gil.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
cython-users...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.