Отдельно разберём 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
TON — LIVE: Telegram Rises in Popularity Rankings
#Telegram#apps
The channel TON — LIVE reports that Telegram has moved up one rank in the list of the most popular apps for 2025.
Source: link
@tonlines
⚡️Trending Apps: New Voting System in Telegram Apps Center
#Telegram#Apps
Trending Apps announces that users can now influence the ranking of Mini Apps through a new voting system in the Telegram Apps Center. Active participants will be rewarded with exclusive SBTs and Telegram Gifts.
Source: link
@tonlines
⚡️Trending Apps: Upcoming Feature in Apps Center
#Telegram#Apps
Trending Apps announced a new feature in the Apps Center, aiming to enhance user engagement by allowing users to influence developments directly. This innovative approach is set to launch within the next 30 days, with more details to be revealed gradually.
Source: link
@tonlines
A partir de hoy amigos, estaré entregando #apps, recursos, plataformas y tips para usar la tecnología a su favor y mejorar las condiciones de #empleo📄📈