Отдельно разберём 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
⭐️#GBPUSD: Weak Market & Bearish Continuation
The charts are full of distraction, disturbance and are a graveyard of fear and greed which shall not cloud our judgement on the current state of affairs in the 📉GBPUSD pair price action which suggests a high likelihood of a coming move down.
📊
🔅GBPUSD Will Move Lower! Short!📉
- - - - - - - -
Take a look at our analysis for 📊GBPUSD.
The market is approaching a significant resistance area 1.352.
Due to the fact that we see a positive bearish reaction from the underlined area, I strongly believe that sellers will manage to push the price all the way down to 1.345 level.
- - - - - - - -
#freesignal#gbpusd
- - - - - - - -
🌐Free Copy Trading: Link
📲Join VIP via Bot:Link
❓Official Contact:@signalprovidercontact
🔅GBPUSD Is Going Up! Long!📈
- - - - - - -
Please, check our technical outlook for 📊GBPUSD.
The market is approaching a key horizontal level 1.349.
Considering the today's price action, probabilities will be high to see a movement to 1.351.
- - - - - - - -
#freesignal#gbpusd
- - - - - - - -
🌐Free Copy Trading: Link
📲Join VIP via Bot:Link
❓Official Contact:@signalprovidercontact
🔅GBPUSD Will Go Down! Short!📉
- - - - - - - -
Please, check our technical outlook for 📊GBPUSD.
The market is testing a major horizontal structure 1.321.
Taking into consideration the structure & trend analysis, I believe that the market will reach 1.315 level soon.
- - - - - - - -
#freesignal#gbpusd
- - - - - - - -
🌐Free Copy Trading: Link
📲Join VIP via Bot:Link
❓Official Contact:@signalprovidercontact