import aiohttp
import asyncio
headers = {
"token":"token3"
}
i=0
async def test():
global i
while i<=1000:
async with aiohttp.ClientSession() as session:
await session.get("http://192.168.39.123:5000/add" , headers=headers)
i+=1
print("请求第",i,"次")
#并发请求10
async def main():
print("main开始")
task_list = [
asyncio.create_task(test()),
asyncio.create_task(test()),
asyncio.create_task(test()),
asyncio.create_task(test()),
asyncio.create_task(test()),
asyncio.create_task(test()),
asyncio.create_task(test()),
asyncio.create_task(test()),
asyncio.create_task(test()),
asyncio.create_task(test()),
]
#两个任务都完成后,会将返回值放到done这个集合中
done,pending = await asyncio.wait(task_list)
asyncio.run(main())