From 13f583ebcf00ccb3b99fde1f7df46a451434e824 Mon Sep 17 00:00:00 2001 From: laffra Date: Wed, 24 Jan 2024 14:07:55 +0100 Subject: [PATCH] avoid copying the queue --- ltk/pubsub.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ltk/pubsub.py b/ltk/pubsub.py index fd64f5a..b045edd 100644 --- a/ltk/pubsub.py +++ b/ltk/pubsub.py @@ -79,9 +79,12 @@ def match(self, message, receiver, receiver_topic, handler): return handled def process_queue(self): - for key, message in list(self.queue.items()): + handled = [] + for key, message in self.queue.items(): if any(self.match(message, *subscriber) for subscriber in self.subscribers): - del self.queue[key] # remove the message from the queue + handled.append(key) + for key in handled: + del self.queue[key] # remove the message from the queue def publish(self, sender, receiver, topic, data): key = f"{_name}-{time.time()}"