reactor-basics.html   [plain text]


<?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: Reactor Overview</title><link href="../howto/stylesheet.css" type="text/css" rel="stylesheet" /></head><body bgcolor="white"><h1 class="title">Reactor Overview</h1><div class="toc"><ol><li><a href="#auto0">Reactor Basics</a></li><li><a href="#auto1">Using the reactor object</a></li></ol></div><div class="content"><span></span><p>
    This HOWTO introduces the Twisted reactor, describes the basics of the
    reactor and links to 
    </p><h2>Reactor Basics<a name="auto0"></a></h2><p> The reactor is the core of the event loop within Twisted -- the loop
    which drives applications using Twisted. The reactor
    provides basic interfaces to a number of services, including
    network communications, threading, and event dispatching.
    </p><p>
    For information about using the reactor and the Twisted event loop, see:
    </p><ul><li>the event dispatching howtos: <a href="time.html">Scheduling</a> and <a href="defer.html">Using Deferreds</a>;</li><li>the communication howtos: <a href="servers.html">TCP
    servers</a>, <a href="clients.html">TCP clients</a>, <a href="udp.html">UDP networking</a> and <a href="process.html">Using
    processes</a>; and</li><li><a href="threading.html">Using threads</a>.</li></ul><p> There are multiple implementations of the reactor, each
    modified to provide better support for specialized features
    over the default implementation.  More information about these
    and how to use a particular implementation is available via
    <a href="choosing-reactor.html">Choosing a Reactor</a>. </p><p>
    Twisted applications can use the interfaces in <code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.application.service.html" title="twisted.application.service">twisted.application.service</a></code> to configure and run the
    application instead of using
    boilerplate reactor code. See <a href="application.html">Using Application</a> for an introduction to
    Application.
    </p><h2>Using the reactor object<a name="auto1"></a></h2><p> You can get to the <code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.internet.reactor.html" title="twisted.internet.reactor">reactor</a></code> object using the following code:</p><pre class="python">
<span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span><span class="py-src-op">.</span><span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span><span class="py-src-newline">
</span><span class="py-src-endmarker"></span></pre><p> The reactor usually implements a set of interfaces, but 
       depending on the chosen reactor and the platform, some of
       the interfaces may not be implemented: </p><ul><li><code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.internet.interfaces.IReactorCore.html" title="twisted.internet.interfaces.IReactorCore">IReactorCore</a></code>: Core (required) functionality.</li><li><code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.internet.interfaces.IReactorFDSet.html" title="twisted.internet.interfaces.IReactorFDSet">IReactorFDSet</a></code>: Use FileDescriptor objects.</li><li><code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.internet.interfaces.IReactorProcess.html" title="twisted.internet.interfaces.IReactorProcess">IReactorProcess</a></code>: Process management. Read the 
        <a href="process.html">Using Processes</a> document for
        more information.</li><li><code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.internet.interfaces.IReactorSSL.html" title="twisted.internet.interfaces.IReactorSSL">IReactorSSL</a></code>: SSL networking support.</li><li><code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.internet.interfaces.IReactorTCP.html" title="twisted.internet.interfaces.IReactorTCP">IReactorTCP</a></code>: TCP networking support. More information
        can be found in the <a href="servers.html">Writing Servers</a>
        and <a href="clients.html">Writing Clients</a> documents.</li><li><code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.internet.interfaces.IReactorThreads.html" title="twisted.internet.interfaces.IReactorThreads">IReactorThreads</a></code>: Threading use and management. More
        information can be found within <a href="threading.html">Threading In Twisted</a>.</li><li><code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.internet.interfaces.IReactorTime.html" title="twisted.internet.interfaces.IReactorTime">IReactorTime</a></code>: Scheduling interface.  More information
        can be found within <a href="time.html">Scheduling Tasks</a>.</li><li><code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.internet.interfaces.IReactorUDP.html" title="twisted.internet.interfaces.IReactorUDP">IReactorUDP</a></code>: UDP networking support. More information
        can be found within <a href="udp.html">UDP Networking</a>.</li><li><code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.internet.interfaces.IReactorUNIX.html" title="twisted.internet.interfaces.IReactorUNIX">IReactorUNIX</a></code>: UNIX socket support.</li></ul></div><p><a href="../howto/index.html">Index</a></p><span class="version">Version: 1.3.0</span></body></html>