python3.10 aiohttp 5000 次 本地 大概需要 10s
import asyncio
import time
import aiohttp
def timed(func):
async def wrapper():
start = time.time()
await func()
print(f"costs: {time.time() - start:.3f} S")
return wrapper
async def req(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
return resp.status
@
timedasync def main():
tasks = [req('
http://httpbin.org/status/200') for _ in range(5000)]
result = await asyncio.gather(*tasks)
print(len(result), ' status: ', result[-1])