Отдельно разберём 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
#GTC/USDT analysis :
#GTC is currently retracing towards the 200 EMA, creating a potential long opportunity on lower time frames (LTF). The price has bounced back from the support zone and is anticipated to test higher levels.
TF : 2h
Entry : $0.418
Target : $0.469
SL : $0.385
#GTC/USDT analysis :
#GTC is currently in a downtrend, marked by a series of lower lows (LLs) and lower highs (LHs). The price is trading within a resistance zone, encountering significant resistance. Consequently, a continuation of the decline is anticipated from this level, with the price likely to test lower levels in the near future.
TF : 4H
Entry : $0.658
Target : $0.560
SL : $0.722
#GTC/USDT analysis :
#GTC has broken below support levels. The price is expected to continue falling and test lower levels, as the higher time frame (HTF) is bearish. Wait for the price to retest the zone before entering a short position.
TF : 4h
Entry : $0.644
Target : $0.596
SL : $0.678
#GTC/USDT UPDATE:
#GTC is now trading around 1.27$. #GTC has broken out a Inverse Head and shoulder pattern on hourly time frame. So the Possible scenario is According to the pattern, we can see short term bullish momentum in it and we can see the price pump 15-20%. Stay tuned with us for further updates✔️
#GTC
The coin looks very good, there is buying, there is reaction from the zones, waiting for further markup of the asset to cover the upper weekly imbalance
📈Sign up on Bybit to trade with me