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?

PaolaJ.
  • 10,872
  • 22
  • 73
  • 111
  • Related question: http://stackoverflow.com/questions/10214042/can-sqlalchemy-be-configured-to-be-non-blocking – stalk May 07 '13 at 13:31

1 Answers1

0

It is hard to answer this question when we don't see the code in _filter function but I'll try to suggest you some directions to research.

First, take a look at python's generators and yield keyword.

Second, take a look at tornado's add_callback method, which allows you to use asynchronous approach and even make use of multithreading.

bazzilic
  • 826
  • 2
  • 8
  • 22