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
- parser: argparse.ArgumentParser
- args: argparse.Namespace
- __init__(module=None, name=None, description=None, command=None, version=None, config_class=None)
- 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
- 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
- prepare_arg_parser()
Pre-init lifecycle method. Extend this if you want custom command-line arguments.
- Return type
- prepare_config()
Pre-init lifecycle method. Extend this if you want to customize config loading.
- Return type
- check_config()
Pre-init lifecycle method. Extend this if you want to customize config validation.
- Return type
- prepare_log()
Pre-init lifecycle method. Extend this if you want to customize logging setup.
- Return type
- prepare()
Lifecycle method where the primary program initialization happens. Use this to fill startup_actions with async startup tasks.
- Return type
- async system_exit()
Lifecycle method that is called if the main event loop exits using
sys.exit()
.- Return type
- 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
- prepare_stop()
Lifecycle method that is called before awaiting
stop()
. Useful for filling shutdown_actions.- Return type
- 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
- manual_stop(exit_code=0)
Tell the event loop to cleanly stop and run the stop lifecycle steps.
- add_startup_actions(*actions)
- Parameters
actions (Union[Awaitable[Any], Iterable[Awaitable[Any]], AsyncIterable[Awaitable[Any]]]) –
- Return type