Три способа выполнить множество задач с asyncio
Функция для примера:
async def do_it(n):
await asyncio.sleep(random.uniform(0.5, 1))
return n
1. Последовательный вызов
async def main():
for i in range(100):
result = await do_it(i)
Такой вызов имеет смысл только тогда, когда результат одной задачи требуется для вызова следующей.
Если они независимы, то это антипаттерн, так как аналогичен простому синхронному вызову по очереди.
2. Упорядоченный результат
async def main():
tasks = [do_it(i) for i in range(100)]
results = await asyncio.gather(*tasks)
Выполняет корутины конкурентно и возвращает результат в виде списка.
Полезен когда требуется получить результаты в том же порядке в котором задачи отправлены.
3. Результат по мере готовности
tasks = [asyncio.create_task(do_it(i)) for i in range(100)]
for cor in asyncio.as_completed(tasks):
result = await cor
Так же выполняет корутины конкурентно, но не гарантирует порядок. Результат возвращается по мере готовности, каждый отдельно.
Полезен когда нужно обработать любой ответ как можно скорее.
#async
Who Is Behind the Alleged Genocide Against Christian (Amhara) Communities in East Arsi, Ethiopia? – and When Will this Stop?
https://borkena.com/2026/03/03/ethiopian-orthodox-christians-who-is-behind-the-alleged-genocide-against-christian-amhara-communities-in-east-arsi-ethiopia/#Ethiopia#humanrights#Arsi
The Unspoken Crisis of Ethiopian Orthodoxy. Read more.
https://borkena.com/2026/03/15/ethipoia-the-unspoken-crisis-of-ethiopian-orthodoxy/#Ethiopia#Orthodox#Arsi
Oromo Liberation Army Points Finger At Abiy Ahmed’s Admin. Over Arsi Massacre. Read more.
https://borkena.com/2026/03/04/ethiopia-oromo-liberation-army-points-finger-at-abiy-ahmeds-admin-over-arsi-massacre/#Ethiopia#OLA#Arsi
Three Orthodox Christians Reportedly killed in Arsi, Oromia region. Read more.
https://borkena.com/2026/02/25/ethiopia-three-orthodox-christians-reportedly-killed-in-arsi-oromia-region/#Ethiopia#News#OrthodoxChristians#Arsi#Orthodox
Death Toll From Arsi Massacre Rise To 34 as killing Orthodox Christian Continues. Read more.
https://borkena.com/2026/03/03/ethiopia-death-toll-from-arsi-massacre-rise-to-34-as-killing-orthodox-christian-continues/#Ethiopia#Arsi#humanrights#Oromia#OrthodoxChristians
Did the World Council Of Churches erred about the Massacre in Arsi?
https://borkena.com/2025/11/15/ethiopia-world-council-of-churches-condemns-all-acts-of-violence-in-ethiopia/#Ethiopia#News#OrthodoxChristianchurch#Ethiopia#WorldCouncilofchurches#Arsi
Systematic Persecution in Oromia: The Role of Militias and Political Actors in Targeting Ethiopian Orthodox Christians. Read more. https://borkena.com/2025/11/05/systematic-persecution-in-oromia-the-role-of-militias-and-political-actors-in-targeting-ethiopian-orthodox-christians/#Ethiopia#Orthodox#OrthodoxChristians#OromiaMassacre#Arsi