Hi,

I have built a python application that uses a COM server from multiple
threads, and despite some initial problems, I got it to work. I found
out (the hard way) that the COM server would have undefined behaviour
if some of its functions were called at the same time form multiple
threads (so it was not thread-safe, although from the registry keys it
looked as if it was), so I made the calls from my application
sequential using locks etc.

Although that is now working fine, I would be really happy if I could
drop this sequential performance hit, from within my multithreaded
python process. After some experimenting, it seems that launching
mulitple python *processes* and using the COM server, works without
any issues (as it was expected, since my understanding is that no
matter what the threading model of a COM server is, when used by
different processes there should be no interference. note I am new to
COM and likely to be wrong). I need to do this without launching
seperate processes, or if thats the only way, then to easily be able
to do inter-proc communication (last resort only)

The COM server is inproc (dll), and I can not modify it.

What I have tried:

- Use DispatchEx instead of Dispatch: this works with other COM
servers, like MS Word and Excel, but not with mine. Probalby has to do
with the fact that they are local servers, whereas mine is inproc.

- CoInitialize, CoInitializeEx with flags: no luck

- using CoGetClassObject instead of CoCreateInstance in pythoncom,
since I read that this would be the way to go if you require multiple
instances of a server: I didnt manage to get it working because the
return type is different to that of CoCreateInstance and I dont know
how to deal with this (ctypes)

- CoCreateInstanceEx: no luck

In short I am looking for a way to always get a new instance of the
COM server when using dispatch, even if it is inproc. I am open to any
suggestions and corrections to my limited COM knowledge
_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to