Отдельно разберём 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
#RIF/USDT analysis :
Following a significant decline of -83% from its all-time high, the price has found support at the $0.0600 level. Subsequently, it has bounced back and successfully broken above the trendline, indicating a confirmation of anticipated bullish momentum. It is expected that the price will continue this upward trajectory and test the previous swing high.
TF : 1W
Entry : $0.1117
Target : $0.3377
SL : $0.0766
#RIF/USDT analysis :
#RIF is trading above the support zone and the 200 EMA. The price is anticipated to rebound from this level and proceed to rise, testing the previous swing high.
TF : 15min
Entry : $0.0977
Target : $0.1007
SL : $0.0956
#RIF yielded an impressive 3,010% return in a few days ⭐
If you used 200x leverage on this signal, you would've made a mind-blowing profit of 12,040%🤩
$50💰 would return $750💵
$50 💰 would return $1,500
💲
$50💰 would return $6,000💰
When you understand the market like we do, every move becomes predictable With 5+ years of trading experience, we spot these moves before they happen 💯
If you want daily signals like this, DM me to join our private group! 👇
@Kevindexter✅
#RIF
I'm expecting roughly this kind of movement on this asset, either with streaming start ups behind our magnets from above.
📈Sign up on Bybit to trade with me