qmi.core.context_singleton.start

qmi.core.context_singleton.start(context_name: str, config_file: str | None = '', init_logging: bool = True, console_loglevel: str | None = None, context_cfg: dict | None = None) QMI_Context

Create and start a global QMI_Context instance.

This function should be called exactly once by the top-level code of the application.

This function performs a number of initialization steps:

  • read the QMI configuration file;

  • initialize logging;

  • create and start a global QMI context.

The context name is a short string, without spaces or strange characters. This name will be used to refer to this context from other processes, as well as for displaying and logging.

The context name should be unique within the workgroup (i.e. among all Python processes that work together via QMI.) If this context acts as a server for other contexts to connect to, its name must be unique. Otherwise, if this context only acts as a client, a duplicate context name is allowed but not recommended.

If config_file is provided, it should be a path to a valid QMI configuration file. The referenced file will be used to load the configuration from. If config_file is an empty string and the environment variable QMI_CONFIG is set, the configuration will be loaded from the file that the environment variable points to. If config_file is None or if it is an empty string and QMI_CONFIG is not set, an empty configuration is used.

The configuration created can be edited by providing a dictionary as an optional input. See config_defs.CfgContext class for possible dict keys and respective values and types that are allowed. Wrong (type) of keys and/or values will raise an exception.

Parameters:
  • context_name – Name of the QMI context.

  • config_file – Optional path to the QMI configuration file.

  • init_logging – Optional flag; set False to skip logging initialization.

  • console_loglevel – Optionally override console_loglevel from config file.

  • context_cfg – Optionally insert or override context(s) in config.contexts.

Returns:

The global QMI_Context object.