I am trying to understand how tornado works. While understanding, I tried to implement a simple coroutine example using tornado.gen
. But the example doesn't seem to work. Any leads on what is going wrong here?
import tornado.web
from tornado import gen
class MainHandler(tornado.web.RequestHandler):
@gen.coroutine
def get(self):
print("Handling starts")
yield tornado.gen.sleep(5)
print("Handling ends")
self.write('Hi')
When I open multiple browser tabs and try to request the server, all the requests except the current one gets blocked and tornado seems to handle these requests in a synchronous way:
Handling starts
Handling ends
Handling starts
Handling ends
Handling starts
Handling ends
Handling starts
Handling ends
Handling starts
Handling ends
Handling starts
Handling ends