[python-win32] The GIL and COM

Brad Johnson Brad.Johnson at ballardtech.com
Wed Jan 21 23:38:02 CET 2009


> > However, while it is waiting for the
> > GIL in the UI thread (when the worker thread has it), it is locked into a
> > WaitForSingleObject call (some layers below PyGILState_Ensure).
> 
> Obviously the GIL can only be held by one thread at a time.  The 
> question then is why your worker thread isn't periodically releasing the 
> GIL so the UI thread can grab it.
I think this is the key. Since my application embeds Python, I call
PyGILState_Ensure in the worker thread to acquire the GIL before doing anything
related to Python. I understand Python releases the GIL periodically, but could
my call be overriding that? If so, how can I run any Python code and hope to
allow other threads to take a stab at getting the GIL?

> The GIL handles this situation just fine, so long as all C code does the 
> right thing.  I don't think we understand you problem well enough to 
> give you any answers yet though.
I understand. I wanted to eliminate as much noise from my post as possible.
Thanks for your help.

~Brad



More information about the python-win32 mailing list