gaoyanping
2019-04-08 18:44
import tornado.ioloop from tornado.httpclient import AsyncHTTPClient N = 3 URL = "http://127.0.0.1:8888/sleep" async def main(): http_client = AsyncHTTPClient() responses = [await http_client.fetch(URL) for i in range(N)] start_time = time.time() tornado.ioloop.IOLoop.current().run_sync(main) print("async", time.time() - start_time) beg = time.time() for i in range(N): requests.get(URL) print(time.time() - beg)
(1)还需要async_server.py
(2)没有import time, requests, gen
(3)没有用装饰器@gen.coroutine修饰main()
你服务端的代码不放出来怎么看呀
Python 高性能 Web 框架 Tornado入门
14233 学习 · 22 问题
相似问题