[Twisted-Python] Creating a COM object in a thread

Hugh Emberson hugh.emberson at gmail.com
Wed Jul 7 23:53:32 EDT 2010

On Thu, Jul 8, 2010 at 9:44 AM, Don Dwiggins <ddwiggins at advpubtech.com> wrote:
>  On 7/5/2010 10:53 PM, Hugh Emberson wrote:
>> I got the order wrong. On further reading of the code, the COM object
>> is created in response to a message from the Twisted thread, so at
>> that point the event loop has iterated at least once.
>> In my case the COM object is wrapped in a C++ wrapper that I don't
>> have the source for, so I don't know exactly what happens in there.
>> That C++ wrapper is then wrapped in a very thin python extension
>> module which doesn't do anything interesting.
> OK.  In my case, the "wrapper" and Python extension is Hammond's
> win32com Dispatch.
> Question: to your knowledge, would it work to run the message pumping
> loop in a different thread from the one that creates and calls the COM
> object?  I think this would simplify things a bit.

You'd have to use a multi-threaded apartment model.  See the
'Processes, Threads, and Apartments' article in MSDN (
http://msdn.microsoft.com/en-us/library/ms693344%28v=VS.85%29.aspx ).
I guess it should work, but I've never tried it.  Please report back
if you try it.


More information about the Twisted-Python mailing list