[Twisted-Python] Creating a daemon from my application
rlotun at gmail.com
Mon Mar 15 11:35:15 EDT 2010
> I want to create a twisted daemon from my application: ...
You want to use twistd. See
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
""" 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()
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.
mobile: +44 (0)7521 310 763
email: rlotun at gmail.com
work: reza at tweetdeck.com
More information about the Twisted-Python