gather misuse (ARCH2032)
Key python.async.gather-misuse · Severity info · Category async
Awaiting independent coroutines separately misses the chance to parallelize them. When losing results on the first failure is unacceptable, use gather(..., return_exceptions=True) instead.
Incorrect
Section titled “Incorrect”async def load(): a = await fetch_a() # sequential, not parallelized b = await fetch_b() return a, bCorrect
Section titled “Correct”import asyncio
async def load(): a, b = await asyncio.gather(fetch_a(), fetch_b()) return a, bRun independent coroutines in parallel with asyncio.gather; add return_exceptions=True to avoid losing results.