Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using gen.task with Tornado for a simple function

Just trying to use the async functions of Tornado - I want to invoke a method from my handler but it keeps telling me that it "got an unexpected keyword argument 'callback'".

class MyHandler(tornado.web.RequestHandler):

    @asynchronous
    @gen.engine
    def get(self):
        response = yield gen.Task(self.dosomething, 'argument')
        self.write(response)
        self.finish()

    def dosomething(self, myargument):
        pass
like image 390
L-R Avatar asked Jul 26 '12 22:07

L-R


1 Answers

Non-blocking function requires callback, where it pass result.

class MyHandler(tornado.web.RequestHandler):

    @asynchronous
    @gen.engine
    def get(self):
        response = yield gen.Task(self.dosomething, 'argument')
        self.write(response)
        self.finish()

    def dosomething(self, myargument, callback):
        return callback(myargument)
like image 56
Nikolay Fominyh Avatar answered Nov 08 '22 10:11

Nikolay Fominyh