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()}"