Отдельно разберём 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
😄Present
➖➖➖➖➖➖
🔘Present (noun) is another word to mean gift. Something you give to someone for a special occasion – like a birthday.
🔜What's the best present you’ve ever received?
🔜I love it when I receive lots of presents.
🔘Present can also be used as a noun to mean now. It is often used with the – the present.
🔜Stop talking about the future, and start living in the present!
🔜The film is set in the present.
🔘Present (adjective) means 'in a particular place' or 'in attendence'.
🔜I was present for all seven classes.
🔜Why wasn't he present for the meeting?
#Present👨🏫@America
➖➖➖➖➖➖➖➖➖➖➖➖
🆕 Crypto News @Money
😁 Crypto Game @Egame
🇺🇸 US News @America
🇯🇵 Japan News @Japan
🇦🇪 UAE News @Dubai
▶️ Popular Movies @Videos
😜 Best Funny Video @Funnys
😄Present
➖➖➖➖➖➖
🔘Present (noun) is another word to mean gift. Something you give to someone for a special occasion – like a birthday.
🔜What's the best present you’ve ever received?
🔜I love it when I receive lots of presents.
🔘Present can also be used as a noun to mean now. It is often used with the – the present.
🔜Stop talking about the future, and start living in the present!
🔜The film is set in the present.
🔘Present (adjective) means 'in a particular place' or 'in attendence'.
🔜I was present for all seven classes.
🔜Why wasn't he present for the meeting?
#Present👨🏫@America
➖➖➖➖➖➖➖➖➖➖➖➖
🆕 Crypto News @Money
😁 Crypto Game @Egame
🇺🇸 US News @America
🇯🇵 Japan News @Japan
🇦🇪 UAE News @Dubai
▶️ Popular Movies @Videos
😜 Best Funny Video @Funnys
👋 Learn how to use the present simple. Look at the images and complete the gap:
We _______ to school on Saturdays.
a. does not go
b. not go
c. don’t go
🤩 EXTRA: Click on our link in bio for more help with this tense.
#learnenglish#present#englishgrammar#englishtips
#Past... is experience
#present... is experiment
#Future...... is expectation
Use your experience in your experiments to achieve your expectations.
@inspireandfunny
🏛Biznes va tadbirkorlik oliy maktabi xodimasi “Mo‘tabar ayol” ko‘krak nishoni bilan taqdirlandi
🎙 Ushbu marosim O‘zbekiston Respublikasi Prezidenti huzuridagi Davlat boshqaruvi akademiyasida bo‘lib o‘tdi, “Mo‘tabar ayol” ko‘krak nishonini topshirish marosimida Dilfuza Rasulova ko‘krak nishoni bilan taqdirlandi.
👥 Tadbirni Oliy Majlis Senatining xotin-qizlar va gender tenglik masalalari qo‘mitasi raisi Malika Kadirxanova hamda Oila va Xotin - qizlar davlat qo‘mitasi raisi o‘rinbosari Mukarram Nurmatovalar ochib berishdi.
↙️ Jami 305 nafar xotin-qizlar mazkur mukofotga munosib deb topildi.
✴️ Ta’kidlash joizki, taqdirlanganlar barcha jabhalarda faol, fidoyi va e’tirof nomiga munosib mo‘tabar ayollardir.
🔍Batafsil
#GraduateSchool#Present#Flowers#ChestPin
Web-site | Telegram | Facebook | Instagram