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

Stefan Behnel stefan_ml at behnel.de
Tue Sep 18 11:12:08 CEST 2007


Greg Ewing wrote:
> Stefan Behnel wrote:
>> Pyrex must still figure
>> out if it needs to acquire the GIL or not. We're fighting Turing here.
> 
> No, we're not. If we were trying to figure out *exactly*
> when the GIL was needed and when it wasn't, under all
> conditions, with no help from the programmer, then we
> would be fighting Turing. But we're taking a conservative
> approach by assuming the GIL is needed unless we can
> prove that it isn't, and relying on declarations to
> fill in Pyrex's gaps in knowledge.
> 
> Declarations are needed in certain key places. Then
> Pyrex checks that everything else is consistent with
> those declarations.

Ah, ok, now I'm getting it. I think I misunderstood your example because it's
actually two things you were trying to catch with the "nogil" annotation:

- "this can safely execute without the GIL", which Pyrex can verify and even
figure out based on function bodies, but which it needs to be told for
external functions

and the second being

- "this *will* be executed without the GIL", which Pyrex cannot know and has
to be told to acquire the GIL if necessary.

I'm not sure the two fit into one keyword.

Maybe a "nopython" annotation for external functions and a smarter Pyrex would
fit the first, while a "nogil" function annotation would match the second?

Stefan




More information about the Pyrex mailing list