nuomimick 2018-12-10 08:07 采纳率: 0%
浏览 962

tornado 请求相同url阻塞

先贴代码

import time

from tornado.gen import coroutine
from tornado.httpclient import AsyncHTTPClient
from tornado.ioloop import IOLoop
from tornado.web import Application, RequestHandler


class MainHandler(RequestHandler):

    @coroutine
    def get(self):
        client = AsyncHTTPClient()
        urls = ['http://www.baidu.com'] * 20
        start = time.time()
        yield [client.fetch(url) for url in urls]
        print(time.time() - start)


def make_app():
    return Application([(r"/", MainHandler), ])


if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    IOLoop.current().start()

我通过浏览器访问http://localhost:8888/ ,get方法中请求了相同的链接50次,但是发现所花费的时间是所有请求耗时的总和。百度了发现请求相同的链接会阻塞,但是没找到解决方案。

试了在链接后面加上不同的参数,结果还是阻塞的。

请问各位大佬有解决方案吗?

  • 写回答

1条回答

  • lyhsdy 2018-12-15 03:42
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 luckysheet
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱