Skip to content

manager

ServerManager

ServerManager()

The manager for all servers.

Source code in src/appl/servers/manager.py
def __init__(self) -> None:
    """Initialize the server manager."""
    self._lock = threading.Lock()
    self._servers: Dict[str, BaseServer] = {}

close_server

close_server(name: str) -> None

Close a server by name.

Source code in src/appl/servers/manager.py
def close_server(self, name: str) -> None:
    """Close a server by name."""
    if name in self._servers:
        self._servers[name].close()
        del self._servers[name]

get_server

get_server(name: Optional[str]) -> BaseServer

Get a server by name. If name is None, get the default server.

Source code in src/appl/servers/manager.py
def get_server(self, name: Optional[str]) -> BaseServer:
    """Get a server by name. If name is None, get the default server."""
    if name == "small":
        name = global_vars.configs.default_servers.small
    elif name == "large":
        name = global_vars.configs.default_servers.large
    if name is None:  # if still None, fall back to default server
        name = global_vars.configs.default_servers.default
        if name is None:  # backward-compatible for now
            name = global_vars.configs.servers.get("default", None)  # type: ignore
            # logger.warning(
            #     "Default server is moved to default_servers.default, "
            #     "please update your config file to set the default server. "
            #     "The current way will be deprecated in the future."
            # )
    if name is None:
        raise ValueError(
            "Default server is not configured. Please set the default server in your config file. "
            "See https://appl-team.github.io/appl/setup/#setup-appl-configuration for more details."
        )
    with self._lock:
        if name not in self._servers:
            server_configs = _get_server_configs(name)
            server = _init_server(**server_configs)
            self.register_server(name, server)
    return self._servers[name]

register_server

register_server(name: str, server: BaseServer) -> None

Register a server with a name.

Source code in src/appl/servers/manager.py
def register_server(self, name: str, server: BaseServer) -> None:
    """Register a server with a name."""
    self._servers[name] = server