Code review fixes

This commit is contained in:
Ian Renton
2026-09-18 07:56:08 +01:00
parent 0fa8cd763d
commit a03e1336c8
18 changed files with 113 additions and 66 deletions
+4 -3
View File
@@ -22,6 +22,7 @@ class LiveDataCache:
self._listeners_lock = threading.Lock()
self._snapshot_dir = snapshot_dir
self._disk_cache = diskcache.Cache(str(snapshot_dir))
self._stop_event = threading.Event()
self._load_snapshot()
self._start_periodic_snapshot(snapshot_interval_sec)
@@ -89,13 +90,13 @@ class LiveDataCache:
def _start_periodic_snapshot(self, interval):
def loop():
while True:
time.sleep(interval)
while not self._stop_event.wait(timeout=interval):
self.save_snapshot()
t = threading.Thread(target=loop, name=f"LiveDataCache-Snapshot-{self._snapshot_dir}")
t = threading.Thread(target=loop, name=f"LiveDataCache-Snapshot-{self._snapshot_dir}", daemon=True)
t.start()
def close(self):
self._stop_event.set()
self.save_snapshot()
self._disk_cache.close()