extension call backs and the GIL
aahz at pythoncraft.com
Mon Sep 29 17:36:03 CEST 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>
>>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
>>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
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"It is easier to optimize correct code than to correct optimized code."
More information about the Python-list