Отдельно разберём 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
#WOO/USDT analysis :
#WOO is currently trading within a channel, and a retracement to the 200 EMA is pending. The price is likely to move upward and test the previous swing high resistance, with expectations for continued upward movement.
TF : 1D
Entry : $0.1629
Target : $0.2186
SL : $0.1469
#WOO Failure Swing Detection 👇
The chart fully and automatically generated by our algorithm.
All drawings are based on only mathematical values and calculations instead of emotions.
Interested?
www.coinlegs.com
#WOO bounced back from the Weekly Trendline and now hitted the Supply zone,in the case of breakout we will see another pump.🚀
otherwise wait to see the price reaction to the trendline again.👀
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
#WOO/USDT UPDATE:
#WOO is now trading around 0.45$. #WOO has broken down of a bear flag on hourly time frame. Now the Possible scenario is according to the pattern, we can see 10-20% dump in this. Keep eye on it 👀Stay tuned with us for further updates✔️
#WOO/USDT UPDATE:
#WOO is now trading around 0.454$. $WOO has formed a bear flag pattern on the hourly time frame. So the Possible scenario is If the price dumps and breaks down the pattern, we can see a dump in it. Keep eye on it👀. Stay tuned with us for further updates✔️