龙卷风异步HTTPClient 在慢速请求上的行为



给出这个基本的例子:

import tornado.gen
import tornado.httpclient
import tornado.web
import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    @tornado.web.asynchronous
    @tornado.gen.engine
    def get(self):
        client = tornado.httpclient.AsyncHTTPClient()
        response = yield tornado.gen.Task(client.fetch, 'http://slowserver-with-a-fake-5s-sleep')
        self.write(str(response.code))
        self.finish()

application = tornado.web.Application([
    (r"/", MainHandler),
])
if __name__ == "__main__":
    application.listen(9999)
    tornado.ioloop.IOLoop.instance().start()

当我按两次"/"时,我可以看到我的人为缓慢的服务器收到两个请求响应,中间有 5 秒。

龙卷风不应该一个接一个地发射两个请求并等待响应吗?为什么 ioloop 被阻止?

龙卷风 2.4

哎哟是的,答案很有趣。这只是 Chrome 将请求排队到同一个网址......

最新更新