[Twisted-Python] Question about TAC apps and TCPClient/Server vs reactor.connect/listenTCP
I'm embarrassed to ask about this, but I think my understanding may be unclear about the differences in how the various TCP connection functions work in Twisted. For the record, I have read the docs at http://twistedmatrix.com/documents/current/core/howto/application.html. But if I missed something key there, please point it out. Got a TAC application, currently implemented using several TCPServer objects. Got a web service running as the main app, with MySQL and AMQP connections also set up the same way, and probably I'll be adding a memcached TCPClient in the near future. The issue is this: I now need to support selectively turning on and off these various components of the software. Also, some services may not always be needed, so specifying as part of the service hierarchy doesn't seem correct. Any suggestions of how to do this? Should I be specifying only "core" stuff as services of the application object, and connecting the others via reactor.connectTCP/listenTCP as needed? Can I add to and remove services from the application object once the reactor starts? Thanks. - Paul
Paul Goins wrote: [...]
Any suggestions of how to do this? Should I be specifying only "core" stuff as services of the application object, and connecting the others via reactor.connectTCP/listenTCP as needed? Can I add to and remove services from the application object once the reactor starts?
Yes, you can add and remove services from the application object once the reactor starts. To remove a service, use the disownServiceParent method of the service (as suggested by the docstring of http://twistedmatrix.com/documents/current/api/twisted.application.service.I...). The docstrings aren't 100% explicit about this, but that will stop the service. As you might guess, you can add services with setServiceParent at any time too. That said, if plain connectTCP/listenTCP are more convenient for you than the corresponding IService implementations, then feel free to use them instead. -Andrew.
participants (2)
-
Andrew Bennetts
-
Paul Goins