Отдельно разберём 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
#LTO/USDT analysis :
#LTO is currently rejecting from a double top resistance zone and showing bearish signs. It is expected to continue declining and test the previous swing low.
TF : 1h
Entry : $0.1124
Target : $0.1079
SL : $0.1151
#LTO | Bounced From Support Level 🧱
How did we find this detection?
1⃣ Visit Detection Analysis at CoinLegs
2⃣ S/R Analysis
3⃣ Variables:
Binance<>USDT<>1h<> Above the S/R Zone<>Weaker
4⃣ Start Analysis
That's it.
Trade easily with free advanced trading tools 💹
#LTO bounced from the Weekly Demand zone,also broken up the trendline and now we are waiting for a pullback to enter the train 🚀
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
#LTO result
2nd target achieved in just 5 hours ✅✅
One more quick profit 9%💰🤑
👉 The longer you wait more you lose profit. Hurry up 🏃♂
☎️ Contact @MichaelStrategiesVip
🛒Coin added - LTO Network#LTO paired with #USDT on Binance looks good for a long-term investment.
It ranks 345 in the CoinMarketCap rating.
Good fundamentals stuff are expected by the end of the year.
The coin has not pumped and is in a neat uptrend.
The price is at the exit from the resistance zone.
Price projector indicates a rise of $0.15.
Support is the $0.05-0.06 zone.
Growth in my experimental portfolio is expected from 70 to 190%.