Отдельно разберём 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
🚀🚀 Another massive profit made in Premium Group and this time it is#ZRX/USDT which crossed All the Profit Targets for an humongous gain of 33%
🗨Contact @futurechief to enter the Binance Futures/Bybit/Kucoin/OKX Premium Signal Group & Receive daily high quality signals by being in the Premium Group
#ZRX/USDT analysis :
#ZRX is in a downtrend, trading below the 200 EMA. The price is currently near the 200 EMA and is expected to reverse from this level, resuming bearish momentum and testing lower levels.
TF : 2h
Entry : $0.3200
Target : $0.2851
SL : $0.3500
#ZRX/USDT analysis :
#ZRX has successfully regained the 200 EMA and the previous support zone following a decline from its swing high. This recovery indicates a potential continuation of its momentum, with the price expected to test previous highs.
TF : 2H
Entry : $0.6490
Target : $0.9025
SL : $0.5250
#ZRX/USDT analysis :
#ZRX is currently consolidating within the resistance zone. The price is anticipated to reject from this level and test the previous support levels, where bullish momentum is expected to emerge.
TF : 15min
Entry : $0.3248
Target : $0.3161
SL : $0.3293
#ZRX/USDT analysis :
#ZRX is currently trading in the resistance zone below the 200 EMA. It's showing rejection at this level, and there's a strong anticipation that the price will continue its downward movement and test previous lows. It's advisable to wait for a confirmation break below the $0.2999 level before considering an entry.
TF : 2H
Entry : $0.2999
Target : $0.2502
SL : $0.3253
#ZRX/USDT analysis -
#ZRX is encountering rejection near a resistance zone, indicating a potential continuation of selling momentum. Prior to any trend reversal, it is anticipated that previous lows will be tested, leading to a potential continuation of the downward movement.
TF : 1D
Entry : $0.3763
Target : $0.2926
SL : $0.4086
🚀🚀 87% Profit on #ZRX/USDT for our Premium Members on Binance Futures/OKX/Bybit - All target completed
👁🗨Contact @primemod to enter the Premium Group and just trade on high quality SPOT & FUTURES Signals