Отдельно разберём TaskGroup, который пришел на замену gather в Python 3.11.
Ключевые отличия
▫️create_task() возвращает объект asyncio.Task, у которого есть соответствюущие методы управления. То есть у нас больше контроля
▫️это контекстный менеджер, который гарантирует что все таски будут остановлены по выходу из контекста
▫️ошибка автоматически отменяет незавершенные задачи,
▫️except* передает нам ExceptionGroup, в котором каждую ошибку можно обработать отдельно
import asyncio
import random
async def do_it() -> str:
if random.random() < 0.1:
raise ValueError('Oops')
delay = random.uniform(0.5, 1.5)
await asyncio.sleep(delay)
return delay
async def main():
try:
async with asyncio.TaskGroup() as tg:
for _ in range(10):
tasks.append(tg.create_task(do_it()))
for t in tasks:
print(t.result())
except *ValueError as e:
for err in e.exceptions:
print(err)
asyncio.run(main())
Рекомендую изучить страницу Coroutines and Tasks из документации, где представлено больше интересных примеров и механизмов
- таймауты
- отмена задач
- создание задач из другого потока
#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