[Twisted-Python] XML-RPC Server in multiservice application

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Sun Nov 27 08:50:22 EST 2011


On 01:35 pm, itamar at itamarst.org wrote:
>On 11/27/2011 06:58 AM, Don Schoeman wrote:
>>I've got a multiservice application running and I'm using the
>>MultiService class from twisted.application.service to do this. All my
>>existing services are setup as children of my multiservice instance.
>>
>>In addition I'd like to run an XML/RPC server as as well. Is it ok if 
>>I
>>instantiate the XML/RPC listening server as per the examples?
>>
>>r = MyXMLRPCServer()
>>reactor.listenTCP(7080, server.Site(r))
>>
>>I've tried this and it does seem to peacefully co-exist alongside the
>>other services, but is this the correct way of implementing the 
>>XML/RPC
>>server on a multiservice application?
>
>A more consistent way, though, would be to have a subclass of Service
>hooked up to your multiservice. This service's startService method 
>would
>do the above, and stopService would do port.stopListening() on the port
>returned from listenTCP.

eg

    from twisted.application.internet import TCPServer

    xmlrpcsvc = TCPServer(7080, server.Site(MyXMLRPCServer())
    xmlrpcsvc.setServiceParent(yourMultiService)

Jean-Paul



More information about the Twisted-Python mailing list