تخطَّ إلى المحتوى

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.

async def load():
a = await fetch_a() # sequential, not parallelized
b = await fetch_b()
return a, b
import asyncio
async def load():
a, b = await asyncio.gather(fetch_a(), fetch_b())
return a, b

Run independent coroutines in parallel with asyncio.gather; add return_exceptions=True to avoid losing results.