program

class mautrix.util.program.Program

Bases: object

A generic main class for programs that handles argument parsing, config loading, logger setup and general startup/shutdown lifecycle.

loop: asyncio.events.AbstractEventLoop
log: mautrix.util.logging.TraceLogger
parser: argparse.ArgumentParser
args: argparse.Namespace
config: mautrix.util.config.BaseFileConfig
__init__(module=None, name=None, description=None, command=None, version=None, config_class=None)
Parameters
Return type

None

module: str
name: str
description: str
command: str
version: str
config_class: type[mautrix.util.config.BaseFileConfig]
startup_actions: Iterable[Awaitable[Any]]
shutdown_actions: Iterable[Awaitable[Any]]
run()

Prepare and run the program. This is the main entrypoint and the only function that should be called manually.

Return type

None

preinit()

First part of startup: parse command-line arguments, load and update config, prepare logger. Exceptions thrown here will crash the program immediately. Asyncio must not be used at this stage, as the loop is only initialized later.

Return type

None

property base_config_path: str
prepare_arg_parser()

Pre-init lifecycle method. Extend this if you want custom command-line arguments.

Return type

None

prepare_config()

Pre-init lifecycle method. Extend this if you want to customize config loading.

Return type

None

load_and_update_config()
Return type

None

check_config()

Pre-init lifecycle method. Extend this if you want to customize config validation.

Return type

None

prepare_log()

Pre-init lifecycle method. Extend this if you want to customize logging setup.

Return type

None

prepare()

Lifecycle method where the primary program initialization happens. Use this to fill startup_actions with async startup tasks.

Return type

None

prepare_loop()

Init lifecycle method where the asyncio event loop is created.

Return type

None

start_prometheus()
Return type

None

async system_exit()

Lifecycle method that is called if the main event loop exits using sys.exit().

Return type

None

async start()

First lifecycle method called inside the asyncio event loop. Extend this if you want more control over startup than just filling startup_actions in the prepare step.

Return type

None

prepare_stop()

Lifecycle method that is called before awaiting stop(). Useful for filling shutdown_actions.

Return type

None

async stop()

Lifecycle method used to stop things that need awaiting to stop. Extend this if you want more control over shutdown than just filling shutdown_actions in the prepare_stop method.

Return type

None

prepare_shutdown()

Lifecycle method that is called right before sys.exit(0).

Return type

None

manual_stop(exit_code=0)

Tell the event loop to cleanly stop and run the stop lifecycle steps.

Parameters

exit_code (int) –

Return type

None

add_startup_actions(*actions)
Parameters

actions (Union[Awaitable[Any], Iterable[Awaitable[Any]], AsyncIterable[Awaitable[Any]]]) –

Return type

None

add_shutdown_actions(*actions)
Parameters

actions (Union[Awaitable[Any], Iterable[Awaitable[Any]], AsyncIterable[Awaitable[Any]]]) –

Return type

None