<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><title>Twisted Documentation: The Basics</title><link href="../howto/stylesheet.css" type="text/css" rel="stylesheet" /></head><body bgcolor="white"><h1 class="title">The Basics</h1><div class="toc"><ol><li><a href="#auto0">Application</a></li><li><a href="#auto1">twistd</a></li><li><a href="#auto2">tap2deb</a></li><li><a href="#auto3">tap2rpm</a></li></ol></div><div class="content"><span></span><h2>Application<a name="auto0"></a></h2><p>Twisted programs usually work with <code class="API">twisted.application.service.Application</code>. This class usually holds all persistent configuration of a running server -- ports to bind to, places where connections to must be kept or attempted, periodic actions to do and almost everything else. It is the root object in a tree of services implementing <code base="twisted.application.service" class="API">IService</code>.</p><p>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, <code>twistd</code>.</p><p><code>Application</code>s are just Python objects, which can be created and manipulated in the same ways as any other object. </p><h2>twistd<a name="auto1"></a></h2><a name="twistd"></a><p>The Twisted Daemon is a program that knows how to run Applications. This program is <code class="shell">twistd(1)</code>. Strictly speaking, <code class="shell">twistd</code> is not necessary -- fetching the application, getting the <code>IService</code> component, calling <code>startService</code>, scheduling <code>stopService</code> when the reactor shuts down, and then calling <code>reactor.run()</code> could be done manually. <code class="shell">twistd(1)</code>, however, supplies many options which are highly useful for program set up.</p><p><code class="shell">twistd</code> supports choosing a reactor (for more on reactors, see <a href="choosing-reactor.html">Choosing a Reactor</a>), logging to a logfile, daemonizing and more. <code class="shell">twistd</code> 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 <code>doc/examples</code> directory. When a straight Python file which defines an <code>Application</code> object called <code>application</code> is used, use the <code class="shell">-y</code> option.</p><p>When <code class="shell">twistd</code> runs, it records its process id in a <code>twistd.pid</code> file (this can be configured via a command line switch). In order to shutdown the <code class="shell">twistd</code> process, kill that pid (usually you would do <code class="shell">kill `cat twistd.pid`</code>). </p><p>As always, the gory details are in the manual page.</p><h2>tap2deb<a name="auto2"></a></h2><p> For Twisted-based server application developers who want to deploy on Debian, Twisted supplies the <code class="shell">tap2deb</code> program. This program wraps a Twisted Application file (of any of the supported formats -- Python, source, xml or pickle) in a Debian package, including correct installation and removal scripts and <code>init.d</code> scripts. This frees the installer from manually stopping or starting the service, and will make sure it goes properly up on startup and down on shutdown and that it obeys the init levels. </p><p> For the more savvy Debian users, the <code class="shell">tap2deb</code> also generates the source package, allowing her to modify and polish things which automated software cannot detect (such as dependencies or relationships to virtual packages). In addition, the Twisted team itself intends to produce Debian packages for some common services, such as web servers and an inetd replacement. Those packages will enjoy the best of all worlds -- both the consistency which comes from being based on the <code class="shell">tap2deb</code> and the delicate manual tweaking of a Debian maintainer, insuring perfect integration with Debian. </p><p> Right now, there is a beta Debian archive of a web server available at <a href="http://twistedmatrix.com/users/moshez/apt">Moshe's archive</a>. </p><h2>tap2rpm<a name="auto3"></a></h2><p><code class="shell">tap2rpm</code> is similar to <code class="shell">tap2deb</code>, except that it generates RPMs for Redhat and other related platforms.</p></div><p><a href="../howto/index.html">Index</a></p><span class="version">Version: 2.5.0</span></body></html>