COM and Python threads
Mark Hammond
mhammond at skippinet.com.au
Sat Dec 11 23:06:29 EST 1999
sven wrote in message <054f0654.99279019 at usw-ex0102-009.remarq.com>...
>I have an app that uses a third pary COM component for some image
>processing (using makepy).
>I'm now trying add multi-threading and it's not playing nice with the
>COM component. When the 2nd thread tries to get an instance of the
>component I get a COM error "Coinitialize not called".
So call pythoncom.CoInitialize() :-)
Each thread needs to call this function. The Pythoncom extensions call it
from the main thread for you.
COMs threading models are complex, and I havent the time to explain them in
detail now (you will just have to by our book when it hits :-), but...
Lookup the docs for CoInitializeEx() in the win32com reference - it is
exalained there. You may also choose to check out the docs at
msdn.microsoft.com. You may prefer to call
pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED). The main Python
thread actually calls CoInitializeEx with the value
COINIT_APARTMENTTHREADED - you can change this by setting sys.coinit_flags
before importing pythoncom. If this actually makes things better or worse
really depends on the control, but if it supports free-threading, then it
should help.
Mark.
More information about the Python-list
mailing list