[Twisted-Python] running several services from a single app

Tim Allen screwtape at froup.com
Tue Mar 29 18:56:51 EDT 2011

On Tue, Mar 29, 2011 at 09:46:11AM +0200, Aljoša Mohorović wrote:
> is there a way to tell reactor to run application and services defined
> so i can skip .tac file and just execute python file?
> maybe something similar to this:
> ----------------------------------------
> application = service.Application("Services")
> factory1 = protocol.ServerFactory()
> factory1.protocol = Protocol1
> internet.TCPServer(8000, factory1).setServiceParent(application)
> factory2 = protocol.ServerFactory()
> factory2.protocol = Protocol2
> internet.TCPServer(9000, factory2).setServiceParent(application)
> # howto make reactor do something like this:
> reactor.run(application)
> ----------------------------------------

It's not clear from your message whether you're using
internet.TCPServer() in your actual production code, or if that's just
something you picked to make a simple example for the mailing-list.

If you really are using internet.TCPServer(), you can just skip the
Application object entirely, and call reactor.listenTCP() instead of
internet.TCPServer(), then reactor.run() at the bottom.

If you've written your own Server or Application subclass that you want
to run, Kevin Horn's answer is probably the one you want.


More information about the Twisted-Python mailing list