[python-win32] COM and Threaded XML-RPC server

Harry Fuecks hfuecks at gmail.com
Mon Dec 13 10:03:42 CET 2004


Hi,

Wondering if someone can give me any pointers with a problem. Trying
to call COM objects from inside an XML-RPC server which is using
Python's threading (via SocketServer.ThreadingMixIn in the standard
library). Gettings errors like;

pywintypes.com_error:(-2147221020, 'Invalid syntax', None, None)

If I use a single threaded server, no problem. Only getting this
problem in combination with SocketServer.ThreadingMixIn.

Example of the server looks like;

#----------------------------------------------------
import SimpleXMLRPCServer, SocketServer
import win32com.client

class ThreadedXmlRpcServer(SocketServer.ThreadingMixIn,
SimpleXMLRPCServer.SimpleXMLRPCServer):
        pass

def listProcesses():
    cses = win32com.client.GetObject("WinMgMts:").InstancesOf("Win32_Process")
    vals = []
    for cs in cses:
        val = cs.Properties_("Caption").Value
        vals.append(val)
    return vals
    
if __name__ == "__main__":
    print listProcesses() # This works...
    
    # This also works, if used - no threads...
    # server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8001))
    
    # This doesnt...
    server = ThreadedXmlRpcServer(("localhost", 8001))
    server.register_function(listProcesses)
    server.serve_forever()
#----------------------------------------------------

And a client if anyone want's to try;

#----------------------------------------------------
import xmlrpclib

server = xmlrpclib.Server('http://localhost:8001')
print server.listProcesses()
#----------------------------------------------------

Apologies in advance if there's something obvious I've missed (like
COM + threading is only possible via the win32api methods) - it's more
than possible I'm guilty of clueless newbieness.

Many thanks


More information about the Python-win32 mailing list