mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 11:34:18 +00:00
❇️ Prevent Baron thread from exiting if a message with no callback is received
This commit is contained in:
parent
1dbefdf6b7
commit
dff5709cc7
1 changed files with 6 additions and 1 deletions
|
@ -21,6 +21,7 @@ class Baron:
|
||||||
self.is_started = False
|
self.is_started = False
|
||||||
|
|
||||||
def listener(self) -> redis.client.PubSub:
|
def listener(self) -> redis.client.PubSub:
|
||||||
|
"""Get the listener of the Baron module."""
|
||||||
return self.listen_thread.listener
|
return self.listen_thread.listener
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
@ -40,9 +41,13 @@ class BaronAlreadyStartedError(Exception):
|
||||||
|
|
||||||
|
|
||||||
class BaronListenerThread(threading.Thread):
|
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):
|
def __init__(self, publisher: redis.Redis, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.listener: redis.client.PubSub = publisher.pubsub()
|
self.listener: redis.client.PubSub = publisher.pubsub()
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self.listener.listen()
|
while True:
|
||||||
|
self.listener.listen()
|
||||||
|
|
Loading…
Reference in a new issue