From dff5709cc7b24db80efe531147e6b641ffac020b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 2 Oct 2020 03:44:46 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9D=87=EF=B8=8F=20Prevent=20Baron=20thread?= =?UTF-8?q?=20from=20exiting=20if=20a=20message=20with=20no=20callback=20i?= =?UTF-8?q?s=20received?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- royalnet/baron/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/royalnet/baron/__init__.py b/royalnet/baron/__init__.py index d841fdd4..5586cf18 100644 --- a/royalnet/baron/__init__.py +++ b/royalnet/baron/__init__.py @@ -21,6 +21,7 @@ class Baron: self.is_started = False def listener(self) -> redis.client.PubSub: + """Get the listener of the Baron module.""" return self.listen_thread.listener def start(self): @@ -40,9 +41,13 @@ class BaronAlreadyStartedError(Exception): class BaronListenerThread(threading.Thread): + """A Thread that creates a PubSub from a Redis instance and constantly listens to it. + + It ignores all messages that do not have an associated callback.""" def __init__(self, publisher: redis.Redis, *args, **kwargs): super().__init__(*args, **kwargs) self.listener: redis.client.PubSub = publisher.pubsub() def run(self) -> None: - self.listener.listen() + while True: + self.listener.listen()