Why doesn't time.sleep run in parallel in a Tornado coroutine?
问题 When I run this handler in a simple Tornado app and make two requests to it with curl , it doesn't run in parallel. It prints out "1 2 3 4 5 1 2 3 4 5", when I want it to print "1 1 2 2 3 3 4 4 5 5". class SleepHandler(RequestHandler): def get(self): for i in range(5): print(i) time.sleep(1) What am I doing wrong? 回答1: The reason for this is that time.sleep is a blocking function: it doesn’t allow control to return to the IOLoop so that other handlers can be run. Of course, time.sleep is