Python tornado gen.coroutine blocks request
<p>I am newbie on tornado and python. A couple days ago i started to write a non-blocking rest api, but i couldn't accomplish the mission yet. When i send two request to this endpoint "localhost:8080/async" at the same time, the second request takes response after 20 seconds! That explains i am doing something wrong.</p>

<pre><code>MAX_WORKERS = 4
class ASYNCHandler(tornado.web.RequestHandler):
    executor = ThreadPoolExecutor(max_workers=MAX_WORKERS)
    counter = 0

    def pow_task(self, x, y):
        time.sleep(10)
        return pow(x,y)

    async def background_task(self):
        future = ASYNCHandler.executor.submit(self.pow_task, 2, 3)
        return future

    @gen.coroutine
    def get(self, *args, **kwargs):
        future = yield from self.background_task()
        response=  dumps({"result":future.result()}, default=json_util.default)
        print(response)


application = tornado.web.Application([
        ('/async', ASYNCHandler),
        ('/sync', SYNCHandler),
    ], db=db, debug=True)  
application.listen(8888)
tornado.ioloop.IOLoop.current().start()
</code></pre>

<p>Never use <code>time.sleep</code> in Tornado code! Use IOLoop.add_timeout to schedule a callback later, or in a coroutine <code>yield gen.sleep(n)</code>.</p>

<p><a href="http://www.tornadoweb.org/en/latest/faq.html#why-isn-t-this-example-with-time-sleep-running-in-parallel" rel="nofollow">http://www.tornadoweb.org/en/latest/faq.html#why-isn-t-this-example-with-time-sleep-running-in-parallel</a></p>

python tornado python-3.5