File size: 468 Bytes
fba3401 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import asyncio
import aiohttp
async def main():
async with aiohttp.ClientSession() as session:
tasks = []
for i in range(5): # 同时5个请求
tasks.append(session.post(
"http://localhost:8000/predict",
json={"text": f"This is test {i}"}
))
responses = await asyncio.gather(*tasks)
for r in responses:
print(await r.json())
asyncio.run(main())
|