[python-win32] COM server with events and multiple threads

Mark Hammond mhammond at skippinet.com.au
Fri Jun 3 12:57:08 CEST 2005


> Thanks for the hints, I will try to modify the sample now to make it
> work using inter thread marshalling.
>
> But isn't it possible to have all the threads in the python
> COM server run in a single MTA?

Not when the hosting application (VB in this case) is not in the MTA.  You
either need to convince VB to live in the MTA (which we have already agreed
you can't), or live with it <wink>.

> Instead of having several worker threads in several STA's in
> the python
> COM server with marshalling between the STA's.

The threads you create are under your control, yes.  So assuming you arrange
for all threads to be in the MTA, you can freely share objects between the
threads.  You can't share the object with any threads not in the MTA
though - which includes the (one and only) VB thread that is not in the MTA.

In this specific case, the problem is we store the object/pointer,
unmarshalled, in the instance.  If we could store the marshalled object, all
other threads would be fine.  I'm not sure now to simply get the MTA
marshalled object in a non-MTA thread, but it may be possible.  Worst case
you could spin a new thread just to marshall it!

> This way, I don't need to implement marshalling between
> threads in the
> python COM server and the marshalling could be done
> implicitely between
> the python COM server (created in the MTA) and the VB6 gui
> (running in
> an STA).

Yes, that is fine - just not for the VB thread.  VB will only have one
thread - so in effect, your "main thread" is not in the free-threaded
apartment, but all other threads can be.

Mark.



More information about the Python-win32 mailing list