asyncio.gather 与 wait:并发等待的两种姿势
gather
results = await asyncio.gather(a(), b(), c())
默认一个失败就整体抛异常。
wait
done, pending = await asyncio.wait(
[a(), b()], timeout=3, return_when=asyncio.FIRST_COMPLETED
)
需要超时或"先完成先处理"时用 wait。
results = await asyncio.gather(a(), b(), c())
默认一个失败就整体抛异常。
done, pending = await asyncio.wait(
[a(), b()], timeout=3, return_when=asyncio.FIRST_COMPLETED
)
需要超时或"先完成先处理"时用 wait。