[Pyrex] pyrex and GIL

Simon Burton simon at arrowtheory.com
Wed Feb 18 06:03:28 CET 2004


On Wed, 18 Feb 2004 17:39:32 +1300 (NZDT)
Greg Ewing <greg at cosc.canterbury.ac.nz> wrote:

> Bob Ippolito <bob at redivi.com>:
> 
> > Have you tried using a callback function that looks like:
> > 
> > cdef callback:
> > 	acquire GIL
> > 	call the 'actual' function (maybe not even a cdef) that might throw an 
> > exception
> > 	release GIL
> 
> If the GIL is not held when the callback is called, there
> will certainly be problems, whether threads are involved
> or not. The above will need to be done in that case.
> 
> I don't know enough about threads to say whether they
> introduce any added complications, though.
> 
> By the way, I have a feature in mind for some future
> version that may help with GIL issues. In the meantime
> you'll have to make the necessary calls yourself.
> 

I have been able to fix this problem by editing the generated c code, and sticking the PyEval_ReleaseThread
just before the return. One must have the GIL to do all the
DECREF cleanup stuff at the end.

Ahhh, maybe I can use a double callback mechanism, with the outer callback just
handling the GIL stuff, without any python variables to DECREF.

Simon.

-- 
Simon Burton, B.Sc.
Licensed PO Box 8066
ANU Canberra 2601
Australia
Ph. 61 02 6249 6940
http://arrowtheory.com 




More information about the Pyrex mailing list