mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-20 22:37:44 +00:00
Code review fixes
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user