module documentation
(source)

Reactor-based Services

Here are services to run clients, servers and periodic services using the reactor.

If you want to run a server service, StreamServerEndpointService defines a service that can wrap an arbitrary IStreamServerEndpoint as an IService. See also twisted.application.strports.service for constructing one of these directly from a descriptive string.

Additionally, this module (dynamically) defines various Service subclasses that let you represent clients and servers in a Service hierarchy. Endpoints APIs should be preferred for stream server services, but since those APIs do not yet exist for clients or datagram services, many of these are still useful.

They are as follows:

  TCPServer, TCPClient,
  UNIXServer, UNIXClient,
  SSLServer, SSLClient,
  UDPServer,
  UNIXDatagramServer, UNIXDatagramClient,
  MulticastServer

These classes take arbitrary arguments in their constructors and pass them straight on to their respective reactor.listenXXX or reactor.connectXXX calls.

For example, the following service starts a web server on port 8080: TCPServer(8080, server.Site(r)). See the documentation for the reactor.listen/connect* methods for more information.

Class TCPServer Undocumented
Class TCPClient Undocumented
Class UNIXServer Undocumented
Class UNIXClient Undocumented
Class SSLServer Undocumented
Class SSLClient Undocumented
Class UDPServer Undocumented
Class UNIXDatagramServer Undocumented
Class UNIXDatagramClient Undocumented
Class MulticastServer Undocumented
Class TimerService Service to periodically call a function
Class CooperatorService Simple service.IService which starts and stops a twisted.internet.task.Cooperator.
Class StreamServerEndpointService A StreamServerEndpointService is an IService which runs a server on a listening port described by an IStreamServerEndpoint.
Function backoffPolicy A timeout policy for ClientService which computes an exponential backoff interval with configurable parameters.
Class ClientService A ClientService maintains a single outgoing connection to a client endpoint, reconnecting after a configurable timeout when a connection fails, either before or after connecting.
Function _maybeGlobalReactor
Class _VolatileDataService Undocumented
Class _AbstractServer
Class _AbstractClient
Variable _clientDoc Undocumented
Variable _serverDoc Undocumented
Class _ReconnectingProtocolProxy A proxy for a Protocol to provide connectionLost notification to a client connection service, in support of reconnecting when connections are lost.
Class _DisconnectFactory A _DisconnectFactory is a proxy for IProtocolFactory that catches connectionLost notifications and relays them.
Variable _defaultPolicy Undocumented
Function _firstResult Return the first element of a generator and exhaust it.
Class _ClientMachine State machine for maintaining a single outgoing connection to an endpoint.
def _maybeGlobalReactor(maybeReactor): (source)
Returnsthe argument, or the global reactor if the argument is None.
_clientDoc = (source)

Undocumented

(type: str)
_serverDoc = (source)

Undocumented

(type: str)
def backoffPolicy(initialDelay=1.0, maxDelay=60.0, factor=1.5, jitter=_goodEnoughRandom): (source)

A timeout policy for ClientService which computes an exponential backoff interval with configurable parameters.

ParametersinitialDelayDelay for the first reconnection attempt (default 1.0s). (type: float)
maxDelayMaximum number of seconds between connection attempts (default 60 seconds, or one minute). Note that this value is before jitter is applied, so the actual maximum possible delay is this value plus the maximum possible result of jitter(). (type: float)
factorA multiplicative factor by which the delay grows on each failed reattempt. Default: 1.5. (type: float)
jitterA 0-argument callable that introduces noise into the delay. By default, random.random, i.e. a pseudorandom floating-point value between zero and one. (type: 0-argument callable returning float)
Returnsa 1-argument callable that, given an attempt count, returns a floating point number; the number of seconds to delay. (type: see ClientService.__init__'s retryPolicy argument.)
Present Since16.1.0
_defaultPolicy = (source)

Undocumented

def _firstResult(gen): (source)

Return the first element of a generator and exhaust it.

MethodicalMachine.upon's collector argument takes a generator of output results. If the generator is exhausted, the later outputs aren't actually run.

ParametersgenGenerator to extract values from
ReturnsThe first element of the generator.
API Documentation for Twisted, generated by pydoctor 20.12.1 at 2021-02-28 19:53:36.