每个URL是否都有自己的会话?我阅读了在Github上找到的aiohttp文档,但我找不到这是否可行。我知道请求是可能的,但不确定如何使用aiohttp。感谢您的帮助,因为我无法找到答案。
sites = ['http://example.com/api/1', 'http://example.com/api/2']
async def fetch(session, site):
print('Fetching: ' + site)
async with session.get(site) as response:
return await response.text()
async def main():
t = []
async with aiohttp.ClientSession() as session:
for site in sites:
task = asyncio.create_task(fetch(session, site))
t.append(task)
await asyncio.gather(*t)
答案 0 :(得分:2)
每个URL是否都有自己的会话?
是的,只需将会话创建移至a = np.matrix(np.zeros((16, 16), dtype = np.int))
协程中即可。
fetch