[python-win32] Running COM server in a specific thread

Manoj Plakal terabaap@yumpee.org
Sat, 24 Nov 2001 20:10:32 -0600


Hello,

Is it possible to force a COM server to execute in a specific
thread rather than have it be spawned in its own thread?

The context: I'm wondering if it's possible to use COM for RPC
between two applications running on the same desktop. The caveat
is that the two apps can be run independently and don't depend
on COM for being created on demand. I realize that standard Win32
IPC mechanisms could be used for this, this is just an exercise
to see if COM can do the whole thing.

So App A runs, spawns thread A-1 to do a GUI, and spawns thread A-2
which exposes some of its functionality as a COM interface.
App B is running concurrently and can then use COM to call methods
in that interface. And I'd like the COM server methods to execute
in the the context of thread A-2 rather than have a fresh
thread spawned by COM.

I tried this out with a test app with two threads, one thread
being a dummy GUI and the other thread containing the loop
from win32com/server/localserver.py. This does prevent spawning
of a new pythonw process to host the server object, but
the object still executes in its own thread.

And supposing that it's not possible to force the COM object
to run in a specific thread, is there a way to have the COM
object communicate to its host application (App A in the
example above)? COM Events? I couldnt' get that to work
(borrowed from the testpycom example in win32com/demos).
I guess standard Win32 IPC like named pipes would work but
again, I was wondering if the whole thing could be done in COM ...

Thanks in advance,

Manoj