Отдельно разберём 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
😁Foundations Of Brazilian Jiu Jitsu No-Gi By Bernardo Faria😁
➡️With this easy-to-learn system, you will build a strong foundation tailored for No-Gi
➡️The fundamentals are the cornerstone of Jiu Jitsu, and in No-Gi, mastering the basics is what leads to victory
➡️Bernardo's game is renowned as the best for older grapplers because it is simple, easy to understand, and doesn't rely on athleticism
$99😍$9.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#BernardoFaria#BJJFanatics#NoGi#BJJ
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Jiu-Jitsu For Old Guys: Guard Retention By Bernardo Faria😁
➡️Unlock the secrets to maintaining a strong guard and thriving on the mats with Bernardo Faria’s proven methods. As a 5x Black Belt World Champion, Faria has crafted this instructional specifically for older grapplers looking to retain guard with minimal energy expenditure while focusing on the fundamentals.
➡️With his in-depth understanding of leverage, timing, and the small details that make a big difference, Faria's Guard Retention series is a game-changer for older practitioners looking to elevate their Jiu-Jitsu without burning out.
➡️Whether you're a seasoned practitioner or just getting started, you'll learn how to guard with confidence and mastery, adapting the principles of BJJ to your unique body and experience level.
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#BernardoFaria#BJJFanatics#Guard#Gi
💁♀️Buy
💁♀️
😁Jiu Jitsu For Old Guys: Entries For Over Under by Bernardo Faria😁
➡️Unlock the secrets to one of the most effective and accessible passing techniques in Brazilian Jiu-Jitsu with Jiu-Jitsu for Old Guys: Entries For Over Under by Bernardo Faria — 5x Black Belt World Champion, BJJ Fanatics Co-founder, and best-selling instructor.
➡️Designed specifically for older practitioners, this series emphasizes technique over athleticism, helping you maintain a competitive edge without relying on explosive power or speed
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#BernardoFaria#Transitions#Gi#BjjFanatics
💁♀️Buy
💁♀️