1
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
3
<title>Twisted Documentation: The Basics</title>
4
<link href="stylesheet.css" rel="stylesheet" type="text/css"/>
8
<h1 class="title">The Basics</h1>
9
<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>
13
<h2>Application<a name="auto0"/></h2>
15
<p>Twisted programs usually work with
16
<code class="API"><a href="http://twistedmatrix.com/documents/10.0.0/api/twisted.application.service.Application.html" title="twisted.application.service.Application">twisted.application.service.Application</a></code>.
17
This class usually holds all persistent configuration of
18
a running server -- ports to bind to, places where connections
19
to must be kept or attempted, periodic actions to do and almost
20
everything else. It is the root object in a tree of services implementing
21
<code class="API"><a href="http://twistedmatrix.com/documents/10.0.0/api/twisted.application.service.IService.html" title="twisted.application.service.IService">IService</a></code>.</p>
23
<p>Other HOWTOs describe how to write custom code for Applications,
24
but this one describes how to use already written code (which can be
25
part of Twisted or from a third-party Twisted plugin developer). The
26
Twisted distribution comes with an important tool to deal with
27
Applications, <code>twistd</code>.</p>
29
<p><code>Application</code>s are just Python objects, which can
30
be created and manipulated in the same ways as any other object.
33
<h2>twistd<a name="auto1"/></h2><a name="twistd" shape="rect"/>
35
<p>The Twisted Daemon is a program that knows how to run Applications.
37
is <code class="shell">twistd(1)</code>. Strictly
38
speaking, <code class="shell">twistd</code> is not necessary --
39
fetching the application, getting the <code>IService</code> component,
40
calling <code>startService</code>, scheduling <code>stopService</code> when
41
the reactor shuts down, and then calling <code>reactor.run()</code> could be
42
done manually. <code class="shell">twistd(1)</code>, however, supplies
43
many options which are highly useful for program set up.</p>
45
<p><code class="shell">twistd</code> supports choosing a reactor (for more on
46
reactors, see <a href="choosing-reactor.html" shape="rect">Choosing a Reactor</a>), logging
47
to a logfile, daemonizing and more. <code class="shell">twistd</code> supports all
48
Applications mentioned above -- and an additional one. Sometimes
49
it is convenient to write the code for building a class in straight
50
Python. One big source of such Python files is the <code>doc/examples</code>
51
directory. When a straight Python file which defines an <code>Application</code>
52
object called <code>application</code> is used, use the <code class="shell">-y</code>
55
<p>When <code class="shell">twistd</code> runs, it records its process id in a
56
<code>twistd.pid</code> file (this can be configured via a command line
57
switch). In order to shutdown the <code class="shell">twistd</code> process, kill that
58
pid (usually you would do <code class="shell">kill `cat twistd.pid`</code>).
61
<p>As always, the gory details are in the manual page.</p>
63
<h2>tap2deb<a name="auto2"/></h2>
66
For Twisted-based server application developers who want to deploy on
67
Debian, Twisted supplies the <code class="shell">tap2deb</code> program. This program
68
wraps a Twisted Application file (of any of the supported formats -- Python,
69
source, xml or pickle)
70
in a Debian package, including correct installation and removal scripts
71
and <code>init.d</code> scripts. This frees the installer from manually
72
stopping or starting the service, and will make sure it goes properly up
73
on startup and down on shutdown and that it obeys the init levels.
77
For the more savvy Debian users, the
78
<code class="shell">tap2deb</code> also generates the source package, allowing her
79
to modify and polish things which automated software cannot detect
80
(such as dependencies or relationships to virtual packages). In addition,
81
the Twisted team itself intends to produce Debian packages for some common
82
services, such as web servers and an inetd replacement. Those packages
83
will enjoy the best of all worlds -- both the consistency which comes
84
from being based on the <code class="shell">tap2deb</code> and the delicate manual
85
tweaking of a Debian maintainer, insuring perfect integration with
89
<h2>tap2rpm<a name="auto3"/></h2>
91
<p><code class="shell">tap2rpm</code> is similar to <code class="shell">tap2deb</code>, except that
92
it generates RPMs for Redhat and other related platforms.</p>
96
<p><a href="index.html">Index</a></p>
97
<span class="version">Version: 10.0.0</span>
b'\\ No newline at end of file'