[Twisted-Python] win32com client in a twisted thread
Andrew Bennetts
andrew at bemusement.org
Mon May 3 19:06:12 MDT 2010
Don Dwiggins wrote:
> I'm running a Windows service with Twisted (xmlrpc), and I've run into
> an odd case.
>
> In a recently implemented method, I create a COM object with
> win32com.client.Dispatch (using a COM DLL that's part of the overall
> application) and make a couple of calls on it, getting a return value.
> This works well, except that the COM object calls a web service, which
> can take a few seconds, so I wanted to defer it.
>
> When I isolate it into a function, and call that with deferToThread, the
> thread appears to die. I tried putting the Dispatch call in the
> mainline, then passing it to the function -- this kills Python (not too
> surprising really).
My memory of this stuff is *very* hazy, but IIRC, if you want to use
win32com stuff from a non-main thread you need to call
pythoncom.CoInitialize() in that thread.
-Andrew.
More information about the Twisted-Python
mailing list