Отдельно разберём 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
#SCRT is rebounding from the support trendline of a falling wedge pattern, showing early signs of recovery.
The 50MA is acting as a resistance barrier above the wedge, limiting upside for now.
A strong breakout of the wedge would confirm bullish momentum and could trigger a solid rally.
#SCRT/USDT analysis :
#SCRT is currently trading within a channel. The price is likely to move upward and test the channel's resistance. It is advisable to wait for a pullback to the support zone for a long entry, as the price is expected to continue its upward movement.
TF : 4h
Entry : $0.1958
Target : $0.2354
SL : $0.1793
#SCRT/USDT analysis :
#SCRT is in a downtrend, consistently trading below the 200 EMA. The price is currently trading in a resistance zone.
It is expected to be rejected from there and will soon continue its downward movement. Wait for the breakout of the $0.1960 level for a short entry; the previous lows will be the target.
TF : 30min
Entry : $0.1960
Target : $0.1742
SL : $0.2094
#SCRT result
1st target achieved in just 1 hour✅
One more quick profit 5%💰🤑
👉 More quick profit signals available in premium channel. Hurry up 🏃♂👇
☎️ Contact @MichaelStrategiesVip