[Twisted-Python] running several services from a single app
is it possible to run several services from a single app? i currently have a few services/apps and would like to put them all into a single app so i can use cx_freeze to create a single exe file for windows to allow easy testing. Aljosa maybe something like this: -------------------------------------------------------- factory1 = protocol.ServerFactory() factory1.protocol = Protocol1 application1 = service.Application("Server1") internet.TCPServer(8000, factory1).setServiceParent(application1) factory2 = protocol.ServerFactory() factory2.protocol = Protocol2 application2 = service.Application("Server2") internet.TCPServer(9000, factory2).setServiceParent(application2) reactor.listenTCP(8000, factory1) reactor.listenTCP(9000, factory2) reactor.run() --------------------------------------------------------
On Mon, Mar 28, 2011 at 8:29 AM, Aljoša Mohorović < aljosa.mohorovic@gmail.com> wrote:
is it possible to run several services from a single app? i currently have a few services/apps and would like to put them all into a single app so i can use cx_freeze to create a single exe file for windows to allow easy testing.
Aljosa
maybe something like this: -------------------------------------------------------- factory1 = protocol.ServerFactory() factory1.protocol = Protocol1 application1 = service.Application("Server1") internet.TCPServer(8000, factory1).setServiceParent(application1)
factory2 = protocol.ServerFactory() factory2.protocol = Protocol2 application2 = service.Application("Server2") internet.TCPServer(9000, factory2).setServiceParent(application2)
reactor.listenTCP(8000, factory1) reactor.listenTCP(9000, factory2)
reactor.run()
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 process, but you can have many services and many clients and servers in a process.
On Mon, Mar 28, 2011 at 7:44 PM, Allen Short
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) ----------------------------------------
On Tue, Mar 29, 2011 at 2:46 AM, Aljoša Mohorović < aljosa.mohorovic@gmail.com> wrote:
On Mon, Mar 28, 2011 at 7:44 PM, Allen Short
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#... 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-ser... 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
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. Tim.
now i looking at adding an wsgi app to this setup. i'm reading http://twistedmatrix.com/documents/current/web/howto/web-in-60/wsgi.html but can't figure out howto get factory for wsgi if i have: === def application(environ, start_response): start_response('200 OK', [('Content-type', 'text/plain')]) return ['Hello, world!'] resource = WSGIResource(reactor, reactor.getThreadPool(), application) === i'm looking for something like "reactor.listenTCP(10000, wsgi_factory)" but don't know howto do it. please point me to proper docs. thanks Aljosa
The factory for twisted.web.resource Resources is twisted.web.server.Site On Thu, Mar 31, 2011 at 4:45 AM, Aljoša Mohorović < aljosa.mohorovic@gmail.com> wrote:
now i looking at adding an wsgi app to this setup. i'm reading http://twistedmatrix.com/documents/current/web/howto/web-in-60/wsgi.html but can't figure out howto get factory for wsgi if i have:
=== def application(environ, start_response): start_response('200 OK', [('Content-type', 'text/plain')]) return ['Hello, world!'] resource = WSGIResource(reactor, reactor.getThreadPool(), application) ===
i'm looking for something like "reactor.listenTCP(10000, wsgi_factory)" but don't know howto do it. please point me to proper docs.
factory = Site(resource) reactor.listenTCP(10000, factory) reactor.run() see here: http://twistedmatrix.com/documents/current/web/howto/web-in-60/dynamic-conte...
thanks
Aljosa
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
I've done something simular in https://github.com/phrearch/hwios/blob/master/services/web_ui/service.py Probably not the best example, but works for me. kind regards, Jeroen On Thursday, March 31, 2011 08:45:49 AM Aljoša Mohorović wrote:
now i looking at adding an wsgi app to this setup. i'm reading http://twistedmatrix.com/documents/current/web/howto/web-in-60/wsgi.html but can't figure out howto get factory for wsgi if i have:
=== def application(environ, start_response): start_response('200 OK', [('Content-type', 'text/plain')]) return ['Hello, world!'] resource = WSGIResource(reactor, reactor.getThreadPool(), application) ===
i'm looking for something like "reactor.listenTCP(10000, wsgi_factory)" but don't know howto do it. please point me to proper docs. thanks
Aljosa
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
On 28 March 2011 16:29, Aljoša Mohorović
is it possible to run several services from a single app?
yes see http://twistedmatrix.com/documents/current/core/howto/application.html and http://twistedmatrix.com/documents/current/api/twisted.application.service.M... Regards, Michael
participants (7)
-
Aljoša Mohorović
-
Allen Short
-
Jasper St. Pierre
-
Jeroen van Veen
-
Kevin Horn
-
Michael Thompson
-
Tim Allen