我正在使用aiohttp客户端会话异步检索网页。
async def fetch(session, url):
#async with session.get(url) as response:
async with getattr(session,"get")(url) as response:
return await response.text()
async with aiohttp.ClientSession() as session: # call 5
html = await fetch(session, 'http://localhost:8081')
还有其他异步方法可以准备数据并处理数据。
响应非常慢。启用异步日志记录。它显示:
获取地址信息localhost:8081,键入= 花了5016.262毫秒:[(, ,6,'',
为什么要花5016毫秒?