[Twisted-Python] win32com client in a twisted thread

Don Dwiggins ddwiggins at advpubtech.com
Mon May 3 18:32:15 MDT 2010


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).

I'm also using dbapi, so I tried it using runInteraction, with no better 
luck.

For what it's worth, here's the code:
>         command = Dispatch('APTAuthorize.clsAuthorizeBatch')
>         model = command.SetupFromConnParms(db['DSN'], db['UserName'], db['Password'])
>         # The returned value is a tuple: the model followed by the params
>         model = model[0]
>         model.PaymentAdjustment = "P"
>         model.BatchId = rsltDict['lPaymentBatchId']
>         model.ShowProgress = True
>         model.AuthorizationType = "CCD"
>         command.Execute(SecurityCode)

Putting logging statements in, I found that it died during the first 
call to "command".  (With no error message or other indication.)

Any thoughts or useful information appreciated,

-- 
Don Dwiggins
Advanced Publishing Technology





More information about the Twisted-Python mailing list