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.Dependable(name, bases, attribs)#
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.Guard#
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#
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.Service#
An abstract base class for services
- static find_free_port()#
- static port_free(port, host='localhost')#
- class jaraco.services.ServiceManager(*args, **kwargs)#
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.
- property running#
Start the service, catching and logging exceptions
Start all services registered with this manager
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 all services of a given class
- class jaraco.services.Subprocess#
Mix-in to handle common subprocess handling
A service is external if there’s another process already providing this service, typically detected by the port already being occupied.
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
‘…’ below should be ‘jaraco.classes’ but for pytest-dev/pytest#3396 >>> X.foo <….properties.NonDataProperty object at …>
- wait_for_pattern(pattern, timeout=5)#
- class jaraco.services.paths.PathFinder#
A base class for locating an executable or executables.
- 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.