service¶
Subpackage start braynsService as a subprocess from Python.
Provides mainly helpers to generate the command line.
service¶
- class LogLevel(value)¶
Bases:
Enum
Server (braynsService backend) log level.
- CRITICAL = 'critical'¶
- DEBUG = 'debug'¶
- ERROR = 'error'¶
- INFO = 'info'¶
- OFF = 'off'¶
- TRACE = 'trace'¶
- WARN = 'warn'¶
- class Plugin(value)¶
Bases:
Enum
All built-in plugins for braynsService.
Plugins are loaded when the backend instance is started and cannot be changed afterward.
The value is the name of the plugin dynamic library (.so).
- ATLAS_EXPLORER = 'braynsAtlasExplorer'¶
- CIRCUIT_EXPLORER = 'braynsCircuitExplorer'¶
- CYLINDRIC_CAMERA = 'braynsCylindricCamera'¶
- DTI = 'braynsDTI'¶
- MOLECULE_EXPLORER = 'braynsMoleculeExplorer'¶
- class property all: list[str]¶
Shortcut to get all the plugin names.
- class Service(uri: str, ssl_context: SslServerContext | None = None, max_clients: int = 1, log_level: LogLevel = LogLevel.WARN, plugins: list[str] = <factory>, executable: str = 'braynsService', env: dict[str, str] = <factory>)¶
Bases:
object
Class used to start a braynsService subprocess.
Use a braynsService executable to start a subprocess. By default it looks for a ‘braynsService’ binary in the PATH but it can be changed.
URI is the websocket server URI (ip:port). Use 0.0.0.0 as wildcard to allow connections from any machine.
SSL server settings can be specified using optional certificate, key, CA and password.
The backend log level can also be specified using
log_level
.Custom environment variables can also be set for the subprocess, for example to override the PATH and load specific libraries.
- Parameters:
uri (str) – Service URI with format ‘host:port’.
ssl_context (SslServerContext | None, optional) – SSL context if secure, defaults to None.
max_clients (int, optional) – Max simultaneous connections authorized, defaults to 1.
log_level (LogLevel, optional) – Process log level, defaults to LogLevel.WARN.
plugins (list[str], optional) – Plugins to load, defaults to all built-in plugins.
executable (str, optional) – braynsService executable, defaults to ‘braynService’.
env (dict[str, str], optional) – Subprocess environment variables, default to empty.
- env: dict[str, str]¶
- executable: str = 'braynsService'¶
- get_command_line() list[str] ¶
Build the command line to start braynsService.
- Returns:
Command line arguments.
- Return type:
list[str]
- max_clients: int = 1¶
- plugins: list[str]¶
- ssl_context: SslServerContext | None = None¶
- start() Process ¶
Start a new process for a braynsService backend.
Return the process which runs the service.
- Returns:
Service process.
- Return type:
- uri: str¶
- class SslServerContext(private_key_file: str | None = None, private_key_passphrase: str | None = None, certificate_file: str | None = None, ca_location: str | None = None)¶
Bases:
object
Server SSL context.
Can be used to start a braynsService instance with SSL enabled. Optional parameters such as the server private key, certificate and trusted CAs can be specified here.
- ca_location: str | None = None¶
- certificate_file: str | None = None¶
- private_key_file: str | None = None¶
- private_key_passphrase: str | None = None¶
manager¶
- class Manager(process: Process, instance: Instance)¶
Bases:
NamedTuple
Wrapper to manage a
Process
connected to anInstance
.Contains a process running braynService and an instance connected to it.
Once done with this object,
stop()
must be called to disconnect the instance and kill the process, using the context manager or by hand.- Parameters:
Create new instance of Manager(process, instance)
- stop() None ¶
Disconnect the instance and kill the process.
process¶
- class Process(args: list[str], env: dict[str, str])¶
Bases:
object
Process running a braynsService backend.
The process must be stopped using terminate() once done with it, otherwise it will run forever. Use context manager (ie with process: …) to avoid mistakes.
The last lines of the process logs can be retreived using
logs
.- property alive: bool¶
Check if the process is still running.
- property logs: str¶
Get the last logs (stdout + stderr) from the process.
- stop() None ¶
Stop the backend service by terminating the process.
Must be called through the context manager (i.e. ‘with’) or manually to avoid the process to run forever.