[Twisted-Python] XML-RPC for paralell clients

Pet petshmidt at googlemail.com
Tue May 19 03:51:39 EDT 2009


after playing with reactor, factory and protocol, I'm trying to
implement XML-RPC server, but it seems that it is not able to handle
several clients in parallel. If I call the slow function with first
client  and then with second client a fast function, second client
will receiver the results after slow function returned. There is no
factory for clients in server.Site() like in Protokoll? What is the
way to do that for XML-RPC?

Thanks for your help!

from twisted.web import xmlrpc, server
from twisted.application import internet

from time import sleep

PORT = 11111

class ExampleXMLRPCProtokoll(xmlrpc.XMLRPC):
    """An example object to be published."""
    def xmlrpc_echo(self, x):
        Return all passed args.
        return x

    def xmlrpc_add(self, a, b):
        Return sum of arguments.
        return a + b

    def xmlrpc_addslow(self, a, b):
        Return sum of arguments. takes time
        return a + b

    def xmlrpc_fault(self):
        Raise a Fault indicating that the procedure should not be used.
        raise xmlrpc.Fault(123, "The fault procedure is faulty.")

class ExampleXMLRPCService(internet.TCPServer):

    def __init__(self):
        print "Starting XML-RPC Service..."
        r = ExampleXMLRPCProtokoll()

def main():
    from twisted.internet import reactor
    r = ExampleXMLRPCProtokoll()
    reactor.listenTCP(PORT, server.Site(r))

if __name__ == '__main__':

More information about the Twisted-Python mailing list