[Twisted-Python] xmlrpc protocoll instanze per connection?

Pet petshmidt at googlemail.com
Wed Aug 4 04:00:16 MDT 2010


Hello,

I've started learning twisted by implementing linereceiver, where for
each new connection a new instance of MyProtocol is created:

class MyFactory(protocol.ServerFactory):
    protocol = MyProtocol
    def __init__(self):
        self.db = adbapi.ConnectionPool()

class MyService(internet.TCPServer):
    def __init__(self):
        print "Starting Service..."
        internet.TCPServer.__init__(self, PORT, MyFactory())

def main():
    reactor.listenTCP(settings.PORT, MyFactory())
    reactor.run()

if __name__ == '__main__':
    main()


Now, for XMLRPC this looks for me like Protocol instance is reused for
all connection. If it is so, can I change this behavior, so I have one
instance of Protocol per connection?
Thanks for help!
Pet



class MyXMLRPCFactory(server.Site):
    def __init__(self):
        self.db = adbapi.ConnectionPool()
        self.r = MyXMLRPCProtokoll(self)
        server.Site.__init__(self,self.r)

class MyXMLRPCService(internet.TCPServer):
   def __init__(self):
       internet.TCPServer.__init__(self, settings.XMLRPC_PORT,
MyXMLRPCFactory())

def main():
   from twisted.internet import reactor
   r = MyXMLRPCProtokoll()
   reactor.listenTCP(settings.XMLRPC_PORT, server.Site(r))
   reactor.run()

if __name__ == '__main__':
   main()




More information about the Twisted-Python mailing list