Отдельно разберём 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
☑️☑️Below you will see the Futures Premium Signals Results for (09th April 2026)
🚀#AIA-USDT - 111% profit
🚀#4-USDT - 154% profit
✅✅Net Profit = 264% Profit
👇🏻Signals Summary
➕Total Signals Sent out - 02
✔️Profitable Signals - 02
✖️Total Signals Lost - 00
◼️Trade cancelled without being executed - 00
✅✅Net Profit - 264% Profit
👁🗨Contact @futurechief to enter the most profitable Futures Premium Signal Group
🎯🎯 Non Stop Huge profit on Premium signals for all Premium Members
🔥🔥#AIA/USDT has crossed all the profit targets and made a great profit of 111%
👁🗨Contact @futurechief to enter the Premium Futures & SPOT Group for daily gains
🚀🚀Raining Profits in the Premium Group
🎯🎯#AIA/USDT has covered all the targets to give an amazing profit of 70% for all Premium Members
👁🗨Contact @futurechief to enter the premium group & make daily gains on Futures as well as Spot Market
🚀🚀🚀160%+ Huge Profit on #AIA/USDT as it has hit all the profit target with great easiness - The trade has been closed today
👁🗨Contact @primemod to enter the premium group & make daily gains
✅✅ 53% Profit on #AIA/USDT for our Premium Members on Futures, OKX, Bybit, Kucoin
🔥🔥 All target completed
👁🗨Contact @primemod to enter the Premium Binance Futures/Bybit/Kucoin/OKX & SPOT Group for daily gains