saturnin.component.single¶
Simplified controller and executor for running a single Saturnin service.
This module provides SingleController and SingleExecutor classes to
streamline the process of configuring, starting, and managing a single
Saturnin service instance. It acts as a higher-level abstraction over
the more detailed DirectController and ThreadController implementations,
allowing for easier integration or standalone execution of services.
Classes¶
- class saturnin.component.single.SingleController(*args, **kwargs)[source]¶
Bases:
TracedMixinA controller that manages a single service, allowing it to be executed either directly in the current thread (using
DirectController) or in a separate thread (usingThreadController).This class simplifies the setup by managing the underlying controller type based on the
directflag.- Parameters:
parser – Optional
ConfigParserinstance to be used for service configuration. IfNone, a new one is created.manager – Optional
ChannelManagerto use. IfNone, a new one is created and managed internally.direct – If
True, the service will be run using an internalDirectController. IfFalse(default), a .`ThreadController` is used.
- configure(*, section: str = 'service') None[source]¶
Configures the service to be run.
This method loads the service configuration from the
config(ConfigParserinstance), validates it, and instantiates the appropriate inner controller (DirectControllerorThreadController) for the specified service.
- join(timeout=None) None[source]¶
Wait until service stops.
- Parameters:
timeout – Floating point number specifying a timeout for the operation in seconds (or fractions thereof).
- Return type:
None
- start(*, timeout: int = 10000) None[source]¶
Starts service.
- Parameters:
timeout (int) – Timeout for starting the service.
None(infinity), or a floating point number specifying a timeout for the operation in seconds (or fractions thereof) [Default: 10s].- Raises:
ServiceError – On error in communication with service.
TimeoutError – When service does not start in time.
- Return type:
None
- stop(*, timeout: int = 10000) None[source]¶
Stop runing service.
- Parameters:
timeout (int) – Timeout for stopping the service.
None(infinity), or a floating point number specifying a timeout for the operation in seconds (or fractions thereof) [Default: 10s].- Raises:
ServiceError – On error in communication with service.
TimeoutError – When service does not stop in time.
- Return type:
None
- config: ConfigParser¶
ConfigParser with service configuration
- controller: ThreadController | DirectController¶
Service controller
- mngr: ChannelManager¶
Channel manager
- class saturnin.component.single.SingleExecutor(*, direct: bool = False)[source]¶
Bases:
objectA context manager for executing a single Saturnin service.
This class simplifies the lifecycle management of a
SingleController, ensuring proper initialization and cleanup (like ZMQ context termination) when used in awithstatement.- Parameters:
direct (bool) – If
True, the underlyingSingleControllerwill be configured to run the service directly in the current thread. IfFalse(default), the service runs in a separate thread.
- configure(cfg_files: list[str], *, section: str = 'service') None[source]¶
Initializes and configures the internal
SingleController.This involves creating a
ChannelManager, instantiating aSingleControllerwith the specifieddirectmode, reading configuration files into the controller’sConfigParser, and then calling the controller’sconfiguremethod.
- run() tuple[Outcome, list[str]] | None[source]¶
Runs the configured service.
If the executor is configured for non-direct (threaded) execution, this method starts the service, waits for it to join (handling KeyboardInterrupt for graceful shutdown), and then returns the execution outcome.
If configured for direct execution, this method starts the service, which will block until it finishes or is interrupted. In direct mode, this method returns
Noneas the outcome is managed within the blocking call.
- controller: SingleController¶
Controller
- mngr: ChannelManager¶
Channel manager