import threading from typing import Optional from config import Singleton class GlobalStore(metaclass=Singleton): def __init__(self): self._id_counter = 0 self._lock = threading.Lock() self._id_map = {} def get_new_id(self) -> int: with self._lock: new_id = self._id_counter self._id_counter += 1 return new_id def add_value(self, id: int, value: str) -> int: with self._lock: self._id_map[id] = value return id def get_value(self, id: int) -> Optional[str]: with self._lock: value = self._id_map.get(id) if value is not None: del self._id_map[id] return value