evilkost/brukva — Issue #20: Client brukva connection
Author: burakdd
Created: 2011-12-13 00:45:01+00:00
State: open

class MessageUpdatesHandler(BaseHandler):
@tornado.web.authenticated
@tornado.web.asynchronous
def post(self):
self.listing_id = self.get_argument("listing_id", None)
self.cursor = self.get_argument("cursor", None)
self.client = brukva.Client()
self.client.connect()
self.client.subscribe(self.listing_id)
self.client.listen(self.on_new_messages)

def on_new_messages(self, messages):
# Closed client connection
if self.request.connection.stream.closed():
return
msg = json.loads(messages.body,'ascii')
self.finish(dict(messages=[msg]))
self.client.unsubscribe(self.listing_id)

def on_connection_close(self):
# unsubscribe user from channel
self.client.unsubscribe(self.listing_id)
self.client.disconnect()
When I long poll using above code and check redis activity seems like when ever client send or posts something it creates new connection, so total connected client increasing on top of each other like 2 client talking and send 10 messages total connected client show 15 or sth like that. Is this bug or should I use different approach while connecting ?