From 227ddbf148be2e14d4b4f27e48a4b091a98f15df Mon Sep 17 00:00:00 2001 From: Hemna Date: Thu, 30 Jan 2025 10:07:28 -0800 Subject: [PATCH] Update StatsStore to use existing lock The base class for StatsStore already creates a lock, use that instead. --- aprsd/threads/stats.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/aprsd/threads/stats.py b/aprsd/threads/stats.py index 6058781..54d789a 100644 --- a/aprsd/threads/stats.py +++ b/aprsd/threads/stats.py @@ -1,8 +1,6 @@ import logging -import threading import time -import wrapt from oslo_config import cfg from aprsd.stats import collector @@ -10,18 +8,15 @@ from aprsd.threads import APRSDThread from aprsd.utils import objectstore CONF = cfg.CONF -LOG = logging.getLogger("APRSD") +LOG = logging.getLogger('APRSD') class StatsStore(objectstore.ObjectStoreMixin): """Container to save the stats from the collector.""" - lock = threading.Lock() - data = {} - - @wrapt.synchronized(lock) def add(self, stats: dict): - self.data = stats + with self.lock: + self.data = stats class APRSDStatsStoreThread(APRSDThread): @@ -31,7 +26,7 @@ class APRSDStatsStoreThread(APRSDThread): save_interval = 10 def __init__(self): - super().__init__("StatsStore") + super().__init__('StatsStore') def loop(self): if self.loop_count % self.save_interval == 0: