Twisted programs usually work with twisted.application.service.Application. This class usually holds all persistent configuration of a running server, such as:
It is the root object in a tree of services implementing twisted.application.service.IService.
Other howtos describe how to write custom code for
Applications, but this one describes how to use already written code (which can be part of Twisted or from a third-party Twisted plugin developer).
The Twisted distribution comes with an important tool to deal with
Applications are just Python objects, which can be created and manipulated in the same ways as any other object.
The Twisted Daemon is a program that knows how to run Applications.
twistd is not necessary.
Fetching the application, getting the
IService component, calling
stopService() when the reactor shuts down, and then calling
reactor.run() could be done manually.
twistd supplies many options which are highly useful for program set up:
twistd supports all Applications mentioned above – and an additional one.
Sometimes it is convenient to write the code for building a class in straight Python.
One big source of such Python files is the examples directory.
When a straight Python file which defines an
Application object called
application is used, use the
twistd runs, it records its process id in a
twistd.pid file (this can be configured via a command line switch).
In order to shutdown the
twistd process, kill that pid.
The usual way to do this would be:
kill `cat twistd.pid`
twistd from daemonizing, you can pass it the
--no-daemon option (or
-n, in conjunction with other short options).
As always, the gory details are in the manual page.