This HOWTO introduces the Twisted reactor, describes the basics of the reactor and links to the various reactor interfaces.
The reactor is the core of the event loop within Twisted – the loop which drives applications using Twisted. The event loop is a programming construct that waits for and dispatches events or messages in a program. It works by calling some internal or external “event provider”, which generally blocks until an event has arrived, and then calls the relevant event handler (“dispatches the event”). The reactor provides basic interfaces to a number of services, including network communications, threading, and event dispatching.
For information about using the reactor and the Twisted event loop, see:
- the event dispatching howtos: Scheduling and Using Deferreds ;
- the communication howtos: TCP servers , TCP clients , UDP networking and Using processes ; and
- Using threads .
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 Choosing a Reactor .
Twisted applications can use the interfaces in twisted.application.service to configure and run the application instead of using boilerplate reactor code. See Using Application for an introduction to Application.
Using the reactor object¶
You can get to the reactor object using the following code:
from twisted.internet import reactor
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:
- IReactorCore : Core (required) functionality.
- IReactorFDSet : Use FileDescriptor objects.
- IReactorProcess : Process management. Read the Using Processes document for more information.
- IReactorSSL : SSL networking support.
- IReactorTCP : TCP networking support. More information can be found in the Writing Servers and Writing Clients documents.
- IReactorThreads : Threading use and management. More information can be found within Threading In Twisted .
- IReactorTime : Scheduling interface. More information can be found within Scheduling Tasks .
- IReactorUDP : UDP networking support. More information can be found within UDP Networking .
- IReactorUNIX : UNIX socket support.
- IReactorSocket : Third-party socket support.