1

At the moment I don't have async code. My Tornado cost looks like

class EmployeeHandler(tornado.web.RequestHandler):
    '''Returns all users which satisfy conditions'''

    def post(self):
        data = tornado.escape.json_decode(self.request.body)
        age = data['age']
        education = data['education']
        result = self._filter(education, age)
        self.write(json.dumps(result))
        self.flush()

    def _filter(self, education, age):
        '''Reads from local database a lot using SQLAlchemy, make joins and is slow'''
        pass

Is there easy way to make this async, to fetch result from filter asynchronously?

4

1 回答 1

0

当我们在函数中看不到代码时,很难回答这个问题,_filter但我会尝试向您建议一些研究方向。

首先,看一下 python 的生成器yield 关键字

其次,看看tornado的add_callback 方法,它允许你使用异步方法,甚至可以使用多线程。

于 2013-10-13T07:38:40.937 回答