Working log streaming

This commit is contained in:
Qubasa
2023-09-27 02:00:20 +02:00
committed by Mic92
parent 98028d121f
commit a8bab7bb96

View File

@@ -79,25 +79,24 @@ class BaseTask(threading.Thread):
class TaskPool: class TaskPool:
def __init__(self) -> None: def __init__(self) -> None:
# self.lock: threading.RLock = threading.RLock() self.lock: threading.RLock = threading.RLock()
self.pool: dict[UUID, BaseTask] = {} self.pool: dict[UUID, BaseTask] = {}
def __getitem__(self, uuid: str | UUID) -> BaseTask: def __getitem__(self, uuid: str | UUID) -> BaseTask:
# with self.lock: with self.lock:
if type(uuid) is UUID: if type(uuid) is UUID:
return self.pool[uuid] return self.pool[uuid]
else: else:
uuid = UUID(uuid) uuid = UUID(uuid)
return self.pool[uuid] return self.pool[uuid]
def __setitem__(self, uuid: UUID, task: BaseTask) -> None:
def __setitem__(self, uuid: UUID, vm: BaseTask) -> None: with self.lock:
# with self.lock: if uuid in self.pool:
if uuid in self.pool: raise KeyError(f"Task with uuid {uuid} already exists")
raise KeyError(f"VM with uuid {uuid} already exists") if type(uuid) is not UUID:
if type(uuid) is not UUID: raise TypeError("uuid must be of type UUID")
raise TypeError("uuid must be of type UUID") self.pool[uuid] = task
self.pool[uuid] = vm
POOL: TaskPool = TaskPool() POOL: TaskPool = TaskPool()