Отдельно разберём 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
#Lazio
Nicola Passanisi, tesoriere del PD locale, annuncia le dimissioni dallo staff del governatore di area FdI Francesco Rocca. Le dimissioni sono state richieste dalla segreteria dem Elly Schlein, dopo che era esploso il caso a livello nazionale
@UltimoraPolitics
La Regione #Lazio revoca il patrocinio del 'Roma Pride 2023': "Non possiamo utilizzare la firma istituzionale a sostegno di manifestazioni volte a promuovere comportamenti illegali, con specifico riferimento alla pratica del cosiddetto utero in affitto" …
La Regione #Lazio revoca il patrocinio del 'Roma Pride 2023': "Non possiamo utilizzare la firma istituzionale a sostegno di manifestazioni volte a promuovere comportamenti illegali, con specifico riferimento alla pratica del cosiddetto utero in affitto"
@UltimoraPolitics
#LAZIO/USDT analysis :
#LAZIO is currently in a downtrend, trading below its 200 Exponential Moving Average (EMA). The price is expected to continue its decline and test lower levels. For a short entry opportunity, wait for the price to test the resistance zone, as a decline is expected from there.
TF : 4h
Entry : $1.165
Target : $0.989
SL : $1.243
#LAZIO/USDT analysis :
#LAZIO is currently trading above the support zone, and the overall trend remains bullish, with the price positioned above the 200 EMA. It is anticipated that the price will continue to rise and test previous highs. For a long entry, it is advisable to wait for a pullback.
TF : 1H
Entry : $1.829
Target : $2.064
SL : $1.704
#LAZIO has a trading range for along time on 4H time frame,we are waiting for breakout retest the broken level ⌛️
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
#Italia#Lazio#Roma
Ti sei perso l'intervista a Andrea Bernaudo (Liberisti Italiani), candidato a Sindaco di Roma? Puoi rivederla su:
Youtube ▶️https://youtu.be/LPMLDi8lefQ
Twitch ▶️https://www.twitch.tv/videos/1074343171
——————
ℹ️ Questa live potrebbe contenere opinioni che non rappresentano il pensiero di Ultimora.net
Il presente contenuto multimediale è curato esclusivamente dal suo autore, che esprime le proprie idee a titolo personale.
#Italia#Lazio#Roma
Ti sei perso l'intervista a Monica Lozzi, candidata a sindaco di Roma? Puoi rivederla su:
Youtube ▶️https://youtu.be/9D_Gt6D8Isc
Twitch ▶️https://www.twitch.tv/videos/1070380604
——————
ℹ️ Questa live potrebbe contenere opinioni che non rappresentano il pensiero di Ultimora.net
Il presente contenuto multimediale è curato esclusivamente dal suo autore, che esprime le proprie idee a titolo personale.