From a8bab7bb96291201a0f600fe9e20770fcdd42775 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Wed, 27 Sep 2023 02:00:20 +0200 Subject: [PATCH] Working log streaming --- pkgs/clan-cli/clan_cli/webui/task_manager.py | 29 ++++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/webui/task_manager.py b/pkgs/clan-cli/clan_cli/webui/task_manager.py index e512eac00..cdbc81551 100644 --- a/pkgs/clan-cli/clan_cli/webui/task_manager.py +++ b/pkgs/clan-cli/clan_cli/webui/task_manager.py @@ -79,25 +79,24 @@ class BaseTask(threading.Thread): class TaskPool: def __init__(self) -> None: - # self.lock: threading.RLock = threading.RLock() + self.lock: threading.RLock = threading.RLock() self.pool: dict[UUID, BaseTask] = {} def __getitem__(self, uuid: str | UUID) -> BaseTask: - # with self.lock: - if type(uuid) is UUID: - return self.pool[uuid] - else: - uuid = UUID(uuid) - return self.pool[uuid] + with self.lock: + if type(uuid) is UUID: + return self.pool[uuid] + else: + uuid = UUID(uuid) + return self.pool[uuid] - - def __setitem__(self, uuid: UUID, vm: BaseTask) -> None: - # with self.lock: - if uuid in self.pool: - raise KeyError(f"VM with uuid {uuid} already exists") - if type(uuid) is not UUID: - raise TypeError("uuid must be of type UUID") - self.pool[uuid] = vm + def __setitem__(self, uuid: UUID, task: BaseTask) -> None: + with self.lock: + if uuid in self.pool: + raise KeyError(f"Task with uuid {uuid} already exists") + if type(uuid) is not UUID: + raise TypeError("uuid must be of type UUID") + self.pool[uuid] = task POOL: TaskPool = TaskPool()