From fc9aeb66527c816b1ac57e6a1ad98acba476fa06 Mon Sep 17 00:00:00 2001 From: elishowk Date: Thu, 10 Jan 2013 15:12:55 +0100 Subject: [PATCH] using parse_response() to prevent pubsub channel closing when empty reference https://github.com/andymccurdy/redis-py/pull/275 --- thoonk/pubsub.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/thoonk/pubsub.py b/thoonk/pubsub.py index 0ded4c2..95c6146 100644 --- a/thoonk/pubsub.py +++ b/thoonk/pubsub.py @@ -10,6 +10,7 @@ from thoonk import feeds, cache from thoonk.exceptions import FeedExists, FeedDoesNotExist, NotListening + class Thoonk(object): """ @@ -154,7 +155,6 @@ def startclass(feed, config=None): pass return self._feeds[feed] - setattr(self, feedtype, startclass) def register_handler(self, name, handler): @@ -300,12 +300,18 @@ def run(self): """ # listener redis object self._pubsub = self.redis.pubsub() + #if self._pubsub.connection is None: + # self._pubsub.connection = self._pubsub.connection_pool.get_connection( + # 'pubsub' + # ) # subscribe to feed activities channel self._pubsub.subscribe((self._finish_channel, 'newfeed', 'delfeed', 'conffeed')) + self._pubsub.parse_response() # subscribe to exist feeds retract and publish for feed in self.redis.smembers("feeds"): self._pubsub.subscribe(self.thoonk._feeds[feed].get_channels()) + self._pubsub.parse_response() self.ready.set() for event in self._pubsub.listen(): @@ -313,6 +319,7 @@ def run(self): if event["channel"] == self._finish_channel: if self._pubsub.subscription_count: self._pubsub.unsubscribe() + self._pubsub.parse_response() elif type == 'message': self._handle_message(**event) elif type == 'pmessage': @@ -326,6 +333,7 @@ def _handle_message(self, channel, data, pattern=None): name, _ = data.split('\x00') self._pubsub.subscribe(("feed.publish:"+name, "feed.edit:"+name, "feed.retract:"+name, "feed.position:"+name, "job.finish:"+name)) + self._pubsub.parse_response() self.emit("create", name) elif channel == 'delfeed':