extension call backs and the GIL
Aahz
aahz at pythoncraft.com
Mon Sep 29 11:36:03 EDT 2003
In article <OWWCyJAWcCe$EwUM at jessikat.fsnet.co.uk>,
Robin Becker <robin at jessikat.fsnet.co.uk> wrote:
>In article <bl93hp$mgc$1 at panix3.panix.com>, Aahz <aahz at pythoncraft.com>
>writes
>>In article <pUnrihASxAe$EwRO at jessikat.fsnet.co.uk>,
>>Robin Becker <robin at jessikat.fsnet.co.uk> wrote:
>>>
>>>I'm trying to better my understanding of multithreading. I believe a
>>>thread that calls an extension must have the GIL. What happens if the
>>>extension then calls back into Python? Can a function or method somehow
>>>'belong' to a different thread? My understanding was that things should
>>>be OK provided the extension code doesn't mess with the GIL (which it
>>>doesn't).
>>
>>You need to reacquire the GIL prior to making the callback.
>
>So does calling an extension release the GIL? I believed the opposite
>for some reason.
Looks like Bernhard has put you on the right track, but just for the
record: calling an extension does not automatically release the GIL; you
need to explicitly call the Py_BEGIN_ALLOW_THREADS macro. I was just
assuming that because you said "accelerator" you were already releasing
the GIL.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
More information about the Python-list
mailing list