[Twisted-Python] win32com client in a twisted thread

Itamar Turner-Trauring itamar at itamarst.org
Mon May 3 18:54:34 MDT 2010


On Mon, 2010-05-03 at 17:32 -0700, 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).


As a test, you should try to make a minimal reproducing example without
Twisted (e.g. just launching a new thread instead of using thread pool).

My guess is that this is something to do with COM's threading rules
(they're complex, apparently - the Python Win32 book has an appendix
discussing the issues), or perhaps a bug in win32com. But that's just a
guess, thus the need for a minimal example.





More information about the Twisted-Python mailing list