diff --git a/aprsd/packets/packet_list.py b/aprsd/packets/packet_list.py index 73eccec..109c7c4 100644 --- a/aprsd/packets/packet_list.py +++ b/aprsd/packets/packet_list.py @@ -62,6 +62,7 @@ class PacketList(objectstore.ObjectStoreMixin): self.data["packets"].popitem(last=False) self.data["packets"][packet.key] = packet + @wrapt.synchronized(lock) def copy(self): return self.data.copy() @@ -73,6 +74,7 @@ class PacketList(objectstore.ObjectStoreMixin): def find(self, packet): return self.data["packets"][packet.key] + @wrapt.synchronized(lock) def __len__(self): return len(self.data["packets"]) diff --git a/aprsd/threads/stats.py b/aprsd/threads/stats.py index f00ec14..9d5c120 100644 --- a/aprsd/threads/stats.py +++ b/aprsd/threads/stats.py @@ -3,6 +3,7 @@ import threading import time from oslo_config import cfg +import wrapt from aprsd.stats import collector from aprsd.threads import APRSDThread @@ -18,6 +19,10 @@ class StatsStore(objectstore.ObjectStoreMixin): lock = threading.Lock() data = {} + @wrapt.synchronized(lock) + def add(self, stats: dict): + self.data = stats + class APRSDStatsStoreThread(APRSDThread): """Save APRSD Stats to disk periodically.""" @@ -32,7 +37,7 @@ class APRSDStatsStoreThread(APRSDThread): if self.loop_count % self.save_interval == 0: stats = collector.Collector().collect() ss = StatsStore() - ss.data = stats + ss.add(stats) ss.save() time.sleep(1) diff --git a/aprsd/utils/objectstore.py b/aprsd/utils/objectstore.py index 1abcaf5..a022373 100644 --- a/aprsd/utils/objectstore.py +++ b/aprsd/utils/objectstore.py @@ -70,8 +70,8 @@ class ObjectStoreMixin: """Save any queued to disk?""" if not CONF.enable_save: return + save_filename = self._save_filename() if len(self) > 0: - save_filename = self._save_filename() LOG.info( f"{self.__class__.__name__}::Saving" f" {len(self)} entries to disk at " @@ -83,7 +83,7 @@ class ObjectStoreMixin: LOG.debug( "{} Nothing to save, flushing old save file '{}'".format( self.__class__.__name__, - self._save_filename(), + save_filename, ), ) self.flush()