[python-win32] coinitialize problem

gijs@globaltrack.com gijs at globaltrack.com
Fri Jul 1 14:36:29 CEST 2005


I'm extending a Python application that uses several com objects and threads. 
The origional programmer set the main thread to multithreaded by doing this:
 * sys.coinit_flags = 0
 * import pythoncom
This is nessacary because otherwise a com (MapObjects2 from ESRI) can't run in 
a thread, but now I need to use another com object, which is running in a 
thread as well. This com object, made by one of our clients, needs to run in a 
single threading model. For some reason, these two com object won't work 
together in one application. MapObjects2 works when the coini_flags is set to 0 
but then the other com object isn't working and the other way around.

I've tried a lot of things to solve this:
 1) don't import pythoncom in the main thread
 -- set the mapobjects thread with coInitializeEx(COINIT_MULTITHREADED)
 -- set the other trhead with CoInitialize()
 2) tried the same things but then with initializing coinit in the mainthread 
with both models
 3) Made a some test programs, but I had always the same problems, except when 
I made 2 functions for the 2 com objects, and started them with beginthreadex 
(like described on page 626 from Mark Hammonds book Python programming on 
win32) and then coinitialize in the functions, but unfortunately, this is not 
an option in our main program

Strange enough, we use 2 other comobjects, adotable for mssql and a com object 
for sending smses, and these two are always working.

Can anyone help me with a solution? and maybe som examples?

Kind Regards,


This message has been scanned for viruses and
dangerous content by Network Sentry, and is
believed to be clean.

More information about the Python-win32 mailing list