[Twisted-Python] Creating a daemon from my application

Reza Lotun rlotun at gmail.com
Mon Mar 15 11:35:15 EDT 2010


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



More information about the Twisted-Python mailing list