Go to the latest version of this document.

# ``twisted`.`application`.`service`.`Service``

class documentation

`class Service: (source)`

Known subclasses: `twisted.application.internet.ClientService`, `twisted.application.internet.CooperatorService`, `twisted.application.internet.StreamServerEndpointService`, `twisted.application.service.MultiService`, `twisted.names.secondary.SecondaryAuthorityService`, `twisted.runner.procmon.ProcessMonitor`, `twisted.words.protocols.jabber.component.Service`, `twisted.application.internet._VolatileDataService`

Implements interfaces: `twisted.application.service.IService`

View In Hierarchy

Base class for services.

Most services should inherit from this class. It handles the book-keeping responsibilities of starting and stopping, as well as not serializing this book-keeping information.

Method | `__getstate__` | Undocumented
Method | `disownServiceParent` | Use this API to remove an `IService` from an `IServiceCollection`.
Method | `privilegedStartService` | Do preparation work for starting the service.
Method | `setName` | Set the name of the service.
Method | `setServiceParent` | Set the parent of the service. This method is responsible for setting the `parent` attribute on this service (the child service).
Method | `startService` | Start the service.
Method | `stopService` | Stop the service.
Instance Variable | `name` | A `str` which is the name of the service or `None`.
Instance Variable | `parent` | An `IServiceCollection` which is the parent or `None`.
Instance Variable | `running` | A `boolean` which indicates whether the service is running.

def __getstate__(self): (source)
overridden in `twisted.runner.procmon.ProcessMonitor`, `twisted.application.internet._VolatileDataService`

Undocumented

def disownServiceParent(self): (source)
from `twisted.application.service.IService`

Use this API to remove an `IService` from an `IServiceCollection`.

This method is used symmetrically with `setServiceParent` in that it sets the `parent` attribute on the child.

Returns
`Deferred` | a `Deferred` which is triggered when the service has finished shutting down. If shutting down is immediate, a value can be returned (usually, `None`).

def privilegedStartService(self): (source)
from `twisted.application.service.IService`
overridden in `twisted.application.internet.StreamServerEndpointService`, `twisted.application.service.MultiService`, `twisted.application.internet._AbstractServer`

Do preparation work for starting the service.

Here things which should be done before changing directory, root or shedding privileges are done.

def setName(self, name): (source)
from `twisted.application.service.IService`

Set the name of the service.

Parameters
name:`str` | Undocumented

Raises
`RuntimeError` | Raised if the service already has a parent.

def setServiceParent(self, parent): (source)
from `twisted.application.service.IService`

Set the parent of the service. This method is responsible for setting the `parent` attribute on this service (the child service).

Parameters
parent:`IServiceCollection` | Undocumented

Raises
`RuntimeError` | Raised if the service already has a parent or if the service has a name and the parent already has a child by that name.

def startService(self): (source)
from `twisted.application.service.IService`
overridden in `twisted.application.internet.ClientService`, `twisted.application.internet.CooperatorService`, `twisted.application.internet.StreamServerEndpointService`, `twisted.application.internet.TimerService`, `twisted.application.service.MultiService`, `twisted.names.secondary.SecondaryAuthorityService`, `twisted.runner.procmon.ProcessMonitor`, `twisted.application.internet._AbstractClient`, `twisted.application.internet._AbstractServer`

Start the service.

def stopService(self): (source)
from `twisted.application.service.IService`
overridden in `twisted.application.internet.ClientService`, `twisted.application.internet.CooperatorService`, `twisted.application.internet.StreamServerEndpointService`, `twisted.application.internet.TimerService`, `twisted.application.service.MultiService`, `twisted.names.secondary.SecondaryAuthorityService`, `twisted.runner.procmon.ProcessMonitor`, `twisted.application.internet._AbstractClient`, `twisted.application.internet._AbstractServer`

Stop the service.

Returns
`Deferred` | a `Deferred` which is triggered when the service has finished shutting down. If shutting down is immediate, a value can be returned (usually, `None`).

name = (source)
from `twisted.application.service.IService`

A `str` which is the name of the service or `None`.

parent = (source)
from `twisted.application.service.IService`
overridden in `twisted.application.service.MultiService`

An `IServiceCollection` which is the parent or `None`.

running: `int` = (source)
from `twisted.application.service.IService`

A `boolean` which indicates whether the service is running.