Question

class RedisHandler(BaseHandler):
@tornado.web.authenticated
@tornado.web.asynchronous
@tornado.gen.engine
def post(self):
    self.client = tornadoredis.Client()
    self.client.connect()
    yield tornado.gen.Task(self.client.subscribe,'notification')
    self.client.listen(self.on_message)

def on_message(self,msg):
    if msg.kind == 'message':
        self.finish(dict(complete=True,message=msg.body))
    return

The above code raises:

RuntimeError: finish() called twice

It may be caused by using async operations without the @asynchronous decorator.

Was it helpful?

Solution

It's probably because you don't unsubscribe/disconnect from Redis when you call self.finish(), and so when another message arrives, on_message() is called again:

def on_message(self,msg):
    if msg.kind == 'message':

        self.finish(dict(complete=True,message=msg.body))

        self.client.unsubscribe('notification')
        self.client.disconnect()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top