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

Kevin Horn kevin.horn at gmail.com
Tue Mar 29 09:22:08 MDT 2011


On Tue, Mar 29, 2011 at 2:46 AM, Aljoša Mohorović <
aljosa.mohorovic at gmail.com> wrote:

> On Mon, Mar 28, 2011 at 7:44 PM, Allen Short <washort at twistedmatrix.com>
> wrote:
> > Get rid of 'application1' and 'application2' and just create a single one
> > named 'application' , delete the last three lines, and this code will
> work
> > just fine as a .tac file. You only need one call to 'Application' per
>
> is it possible to setup this without .tac file?
> i don't know howto create an exe file using cx_freeze from .tac file.
>
> 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)
> ----------------------------------------
>
>
Sadly it's undocumented, but you're probably looking for:
http://twistedmatrix.com/documents/current/api/twisted.application.app.html#startApplication

The only examples I can find of it's use are by people who want to start a
"tac" type application as a WinNT Service, but I think it would work for
your purposes as well.

Here's an example:
http://foobar.lu/wp/2007/06/27/runnning-a-twisted-application-as-windows-service/

You can see the application object is created as normal (though in the
example it happens in a different file and is imported), then
startApplication is called, then reactor.run().

Good Luck!

Kevin Horn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20110329/f9a774de/attachment.html>


More information about the Twisted-Python mailing list