Closed Fly-Playgroud closed 4 months ago
I think maybe use while loop to keep running
solve code:
async def _pubsub_listener(self) -> None:
# redis-py does not listen to the pubsub connection if there are no channels subscribed
# so we need to wait until the first channel is subscribed to start listening
while True:
await self._ready.wait()
async for message in self._pubsub.listen():
if message["type"] == "message":
event = Event(
channel=message["channel"].decode(),
message=message["data"].decode(),
)
await self._queue.put(event)
self._ready.clear()
This looks like a great solution! Can you make a PR?
This looks like a great solution! Can you make a PR?
ok, I will do it
merged,
https://github.com/encode/broadcaster/blob/22e8b2afb131321dcd0a9a06be2d860849cfbe5a/broadcaster/_backends/redis.py#L43-L53
the redis-backend pub-listener only just listen once, if channels unsubscribed until here no channels to subscribe, this
async.Task
will exited. Even if new subscriptions come in later, no messages can be listened because of it has eixted.