Отдельно разберём 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
🌟 Applications for YPIP 2026 are NOW OPEN! 🌟
Are you ready to launch your professional journey next summer?
The Young Professional Internships Program (YPIP) provides university students from Uzbekistan the opportunity to strengthen their professional skills through summer internships with leading companies, NGOs, and organizations in Tashkent.
✅ Participants will:
- Gain hands-on work experience in business, STEM, and other fields
- Take part in professional development workshops and field trips
- Network with peers, mentors, and industry leaders
- Receive guidance from established professionals
🌠 Eligibility:
- Commitment to a career in business or STEM
- Citizens of Uzbekistan, currently residing in the country
- Enrolled at a local university as a 3rd or 4th-year student, or graduating by May 2026
- Proficiency in English
⏰ Application Deadline: December 8, 2025
🔗Link to the application
Young Professional Internships Program (YPIP) is funded by the U.S. Embassy in Tashkent and implemented by American Councils for International Education.
#YPIP2026#Internships#YouthOpportunities
🎓Applications for YPIP 2026 are NOW OPEN!
Are you ready to launch your professional journey next summer?
The Young Professional Internships Program (YPIP) provides university students from Uzbekistan the opportunity to strengthen their professional skills through summer internships with leading companies, NGOs, and organizations in Tashkent.
🟣Participants will:
- Gain hands-on work experience in business, STEM, and other fields
- Take part in professional development workshops and field trips
- Network with peers, mentors, and industry leaders
- Receive guidance from established professionals
✔️Eligibility:
- Commitment to a career in business or STEM
- Citizens of Uzbekistan, currently residing in the country
- Enrolled at a local university as a 3rd or 4th-year student, or graduating by May 2026
- Proficiency in English
⏰ Application Deadline: December 8, 2025
📌Link to the application
Young Professional Internships Program (YPIP) is funded by the U.S. Embassy in Tashkent and implemented by American Councils for International Education.
#YPIP2026#Internships#YouthOpportunities