Отдельно разберём 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
Let's end Day 3 of #WazirX's 6th Anniversary with a Giveaway 🥳
🎁 100 lucky winners will win 85 Million $LOVELY each!
Giveaway Details 👉https://x.com/WazirXIndia/status/1765747308648694243?s=20
🔜 More rewards coming your way!
🔴 The total $ETH holding of #WazirX exploiter has risen to 59,097 $ETH ($201M)!
Among these tokens:
➡️ 15,298 $ETH ($52M) was stolen directly from the exchange;
➡️ 43,799 $ETH ($149M) was acquired by dumping various assets, notably 5.43T $SHIB ($90.2M), 20.5M $MATIC ($10.2M), and 640.27B $PEPE ($7.48M).
The exploiter has not made the next moves with these $ETH and only has around ~$12M in altcoins such as $CHR, $CELR, $OOKI, and $FRONT.
Follow @spotonchain and set alerts to see what the exploiter will do next via https://platform.spotonchain.ai/en/platform/entity/2220
Trump Launches Memecoin TRUMP on Solana
Donald Trump has launched his memecoin, $TRUMP, on the Solana blockchain, coinciding with his upcoming inauguration. The token saw a rapid price surge, with one trader earning $29.8 million from an initial investment of $1.09 million. The memecoin achieved a market cap of $11 billion shortly after its release, outperforming several notable cryptocurrencies. Amidst this, WazirX froze $3 million of stolen funds, and the U.S. Supreme Court upheld potential TikTok bans.
#Trump#Memecoin#Blockchain#Solana#Crypto#Bitcoin#CyberSecurity#WazirX#TikTok#MarketCap#Investment#Trader#Cryptocurrency#Trading#EconomicNews#SolanaBlockchain#DigitalAssets#MarketSurge#Inauguration#Finance#NFT