[Twisted-Python] Creating a daemon from my application

gary clark burslem2001 at yahoo.com
Mon Mar 15 12:03:09 MDT 2010


Yeh I have to install them and create a setup.py to find the path.

--- On Mon, 3/15/10, gary clark <burslem2001 at yahoo.com> wrote:

> From: gary clark <burslem2001 at yahoo.com>
> Subject: Re: [Twisted-Python] Creating a daemon from my application
> To: "Twisted general discussion" <twisted-python at twistedmatrix.com>
> Date: Monday, March 15, 2010, 12:19 PM
> Hello,
> 
> I compacted the server code initialization into the
> ServerContextFactory:
> 
> 
> from nfdmessenger import ServerContextFactory
> from twisted.internet import ssl, reactor
> 
> 
> if __name__ == '__main__':
>     serverContext =  ServerContextFactory()
>     reactor.listenSSL(2000, serverContext,
> serverContext)
>     reactor.run()
> 
> 
> Running the below:
> 
> python nfddaemon.py
> 
> Looks goods and runs as expected:
> 
> 
> I then moved the code into a tac file:
> 
> from twisted.application import service,internet
> from nfdmessenger import ServerContextFactory
> from twisted.internet import ssl, reactor
> 
> 
> def get_service():
>     serverContext =  ServerContextFactory()
>     return reactor.listenSSL(2000, serverContext,
> serverContext)
> 
> application=service.Application('nfdm')
> service=get_service()
> service.setServiceParent(application)
> 
> 
> When I attempt to run:
> 
> >twistd -r epoll -y nfddaemon.tac
> 
> File "nfddaemon.tac", line 2, in <module>
>     from nfdmessenger import
> ServerContextFactory
> exceptions.ImportError: No module named nfdmessenger
> 
> It looks like it cannot find the module? Do I have to set
> the path?
> Also not too sure about my getService routine...well
> suspect.
> 
> Thanks,
> Garyc
> 
> --- On Mon, 3/15/10, gary clark <burslem2001 at yahoo.com>
> wrote:
> 
> > From: gary clark <burslem2001 at yahoo.com>
> > Subject: Re: [Twisted-Python] Creating a daemon from
> my application
> > To: "Twisted general discussion" <twisted-python at twistedmatrix.com>
> > Date: Monday, March 15, 2010, 11:14 AM
> > Thanks Reza I wil give it a crack.
> > 
> > Much appreciated,
> > Garyc
> > 
> > 
> > --- On Mon, 3/15/10, Reza Lotun <rlotun at gmail.com>
> > wrote:
> > 
> > > From: Reza Lotun <rlotun at gmail.com>
> > > Subject: Re: [Twisted-Python] Creating a daemon
> from
> > my application
> > > To: "Twisted general discussion" <twisted-python at twistedmatrix.com>
> > > Date: Monday, March 15, 2010, 10:35 AM
> > > Hi,
> > > 
> > > > I want to create a twisted daemon from my
> > application:
> > > ...
> > > 
> > > You want to use twistd. See
> > > http://twistedmatrix.com/documents/current/core/howto/basics.html#auto1
> > > 
> > > The process is roughly:
> > > 
> > > 1) create a myapp.tac file which essentially
> loads in
> > your
> > > server and
> > > wraps it in an application
> > > 2) run something like:
> > >        $ twistd -r epoll -y
> > > myapp.tac
> > > which will daemonize your server (using the
> epoll
> > reactor)
> > > and write
> > > its pid to twistd.pid
> > > 
> > > A .tac file could look something like:
> > > 
> > > from twisted.application import service,
> internet
> > > from myapp import MyAppServer
> > > 
> > > def get_service():
> > >     """ Return a service suitable for creating
> an
> > > application object. """
> > >     site = MyAppServer()
> > >     port = 2000
> > >     return internet.TCPServer(2000, site)
> > > 
> > > application =
> > service.Application('MyApplicationName')
> > > # attach the service to its parent application
> > > service = get_service()
> > > service.setServiceParent(application)
> > > 
> > > Also, keep in mind you might want to use twistd
> in
> > > conjunction with a
> > > process runner (http://dustin.github.com/2010/02/28/running-processes.html).
> > > That is, if you're using something like Ubuntu,
> you
> > > probably want to
> > > run twistd using upstart.
> > > 
> > > Hope this helps.
> > > 
> > > Reza
> > > 
> > > -- 
> > > Reza Lotun
> > > mobile: +44 (0)7521 310 763
> > > email:  rlotun at gmail.com
> > > work:   reza at tweetdeck.com
> > > twitter: @rlotun
> > > 
> > > _______________________________________________
> > > Twisted-Python mailing list
> > > Twisted-Python at twistedmatrix.com
> > > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> > > 
> > 
> > 
> > _______________________________________________
> > Twisted-Python mailing list
> > Twisted-Python at twistedmatrix.com
> > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> > 
> 
> 
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> 





More information about the Twisted-Python mailing list