[python-win32] The GIL and COM

Brad Johnson Brad.Johnson at ballardtech.com
Thu Jan 22 18:49:10 CET 2009


> So one your thread has acquired the GIL, one of 3 things happens:
> 
> * It returns quickly and the GIL is released.
> * It executes many many instructions: every 'n' instructions Python will 
> temporarily release the GIL for you.
> * It calls some other blocking function.  This other blocking function 
> must release the GIL before blocking, then re-aquire it when it needs to 
> re-enter Python.

You're gonna love this one, Mark. It's number 3, and it's *pywin32* May I
present exhibit A:

PyObject *PyITypeInfo::GetContainingTypeLib()
{
	ITypeInfo *pMyTypeInfo = GetI(this);
	if (pMyTypeInfo==NULL) return NULL;

	ITypeLib *ptlib;
	unsigned index;
	SCODE sc = pMyTypeInfo->GetContainingTypeLib(&ptlib, &index);
	if (FAILED(sc))
		return PyCom_BuildPyException(sc, pMyTypeInfo, IID_ITypeInfo);

	PyObject *ret = PyTuple_New(2);
	PyTuple_SetItem(ret, 0, PyCom_PyObjectFromIUnknown(ptlib, IID_ITypeLib));
	PyTuple_SetItem(ret, 1, PyInt_FromLong(index));
	return ret;
}

Unremarkable until you notice the call into GetContainingTypeLib is not wrapped
in PY_INTERFACE_PRECALL and PY_INTERFACE_POSTCALL. I'll add those lines in and
make sure my problem is fixed. I think we have a bug.




More information about the python-win32 mailing list