Welcome to jaraco.services documentation!

This module provides a Service base class for modeling management of a service, typically launched as a subprocess.

The ServiceManager (deprecated) acts as a collection of interdependent services, can monitor which are running, and will start services on demand. The use case for ServiceManager has been superseded by the more elegant pytest fixtures model.

class jaraco.services.ServiceManager(*args, **kwargs)

Bases: list

A class that manages services that may be required by some of the unit tests. ServiceManager will start up daemon services as subprocesses or threads and will stop them when requested or when destroyed.

register(service)
property running
start(service)

Start the service, catching and logging exceptions

start_all()

Start all services registered with this manager

start_class(class_)

Start all services of a given class. If this manager doesn’t already have a service of that class, it constructs one and starts it.

stop(service)
stop_all()
stop_class(class_)

Stop all services of a given class

class jaraco.services.Guard

Bases: object

Prevent execution of a function unless arguments pass self.allowed()

>>> class OnlyInts(Guard):
...     def allowed(self, *args, **kwargs):
...         return all(isinstance(arg, int) for arg in args)
>>> @OnlyInts()
... def the_func(val):
...     print(val)
>>> the_func(1)
1
>>> the_func('1')
>>> the_func(1, '1') is None
True
allowed(*args, **kwargs)
class jaraco.services.HTTPStatus

Bases: object

Mix-in for services that have an HTTP Service for checking the status

build_url(path, host='localhost')
proto = 'http'
status_path = '/_status/system'
wait_for_http(host='localhost', timeout=15)
class jaraco.services.Subprocess

Bases: object

Mix-in to handle common subprocess handling

class PortFree(port=None)

Bases: jaraco.services.Guard

allowed(service, *args, **kwargs)
assert_running()
get_log()
is_external()

A service is external if there’s another process already providing this service, typically detected by the port already being occupied.

is_running()
log_root

Much like the property builtin, but only implements __get__, making it a non-data property, and can be subsequently reset.

See http://users.rcn.com/python/download/Descriptor.htm for more information.

>>> class X(object):
...   @NonDataProperty
...   def foo(self):
...     return 3
>>> x = X()
>>> x.foo
3
>>> x.foo = 4
>>> x.foo
4
stop()
wait_for_pattern(pattern, timeout=5)
class jaraco.services.Dependable(name, bases, attribs)

Bases: type

Metaclass to keep track of services which are depended on by others.

When a class (cls) is created which depends on another (dep), the other gets a reference to cls in its depended_by attribute.

class jaraco.services.Service

Bases: object

An abstract base class for services

depends = {}
static find_free_port()
is_running()
static port_free(port, host='localhost')
start()
stop()
class jaraco.services.paths.PathFinder

Bases: object

A base class for locating an executable or executables.

DEV_NULL = <_io.TextIOWrapper name='/dev/null' mode='r+' encoding='UTF-8'>
args = []

Additional args to pass to the exe when testing for its suitability

candidate_paths = ['']

Potential roots to search for self.exe

abstract property exe

The target executable

classmethod find_root()
classmethod find_valid_roots()

Generate valid roots for the target executable based on the candidate paths.

classmethod is_valid_root(root)
classmethod resolve()

Resolve an executable or raise RuntimeError if one cannot be found.

Indices and tables