cobald.daemon.runners.service module

class cobald.daemon.runners.service.ServiceRunner(accept_delay: float = 1)[source]

Bases: object

Runner for coroutines, subroutines and services

The service runner prevents silent failures by tracking concurrent tasks and therefore provides safer concurrency. If any task fails with an exception or provides unexpected output values, this is registered as an error; the runner will gracefully shut down all tasks in this case.

To provide async concurrency, the runner also manages common async event loops and tracks them for failures as well. As a result, async code should usually use the “current” event loop directly.

accept()[source]

Start accepting synchronous, asynchronous and service payloads

Since services are globally defined, only one ServiceRunner may accept() payloads at any time.

adopt(payload, *args, flavour: module, **kwargs)[source]

Concurrently run payload in the background

If *args* and/or **kwargs are provided, pass them to payload upon execution.

execute(payload, *args, flavour: module, **kwargs)[source]

Synchronously run payload and provide its output

If *args* and/or **kwargs are provided, pass them to payload upon execution.

shutdown()[source]

Shutdown the accept loop and stop running payloads

class cobald.daemon.runners.service.ServiceUnit(service, flavour)[source]

Bases: object

Definition for running a service

Parameters:
  • service – the service to run

  • flavour – runner flavour to use for running the service

property running
start(runner: MetaRunner)[source]
classmethod units() Set[ServiceUnit][source]

Container of all currently defined units

cobald.daemon.runners.service.service(flavour)[source]

Mark a class as implementing a Service

Each Service class must have a run method, which does not take any arguments. This method is adopt()ed after the daemon starts, unless

  • the Service has been garbage collected, or

  • the ServiceUnit has been cancel()ed.

For each service instance, its ServiceUnit is available at service_instance.__service_unit__.