-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Description
What happens when connection to Redis goes down or timeouts while listening to PubSub messages via a long running "pubsub.listen()" ?
Any tips how i can gracefully handle / restart interrupted connection?
I do appreciate your help!
This is the relevant code:
class Listener(threading.Thread):
def __init__(self, r, channels):
threading.Thread.__init__(self)
self.redis = r
self.pubsub = self.redis.pubsub()
try:
self.pubsub.subscribe(channels)
except ConnectionError:
print self, "Redis is down"
def work(self, item):
print item['channel'], ":", item['data']
def run(self):
for item in self.pubsub.listen():
if item['data'] == "KILL":
self.pubsub.unsubscribe()
print self, "unsubscribed and finished"
break
else:
self.work(item)hosjiu1702
Metadata
Metadata
Assignees
Labels
No labels