Отдельно разберём 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
#selfimprovement
Emotional Intelligence: Why It Matters More Than IQ🧠
You’re not as rational as you think you are. None of us are. Neuroscience shows that our amygdala, the brain’s emotional center, often fires before the prefrontal cortex—our logical HQ—has even had time to weigh in.
Finally reached 300 members
Thank you so much for all your wonderful support 😊😍
#300Members#ipersonalgrowths
#selfimprovement#Mentorship
PS : Once Again Thanks all dear Amazing people 🌻🌿 Let's go ahead 😀 fulfill You're Dream and Ambitious
Stay Connect 🌼💫 Keep Supporting 💛
As you may have noticed one month into the new year, traditional New Year’s resolutions often fail because people set vague or too big goals, rely only on willpower, and don’t have a clear plan. Small, specific changes and building habits step by step are supposed to work better. 🔄
[Read more]
@googlefactss
#NewYearsResolutions#Habits#Goals#SelfImprovement
The Power of Your Thoughts - #stoicismquotes#powerofthought#selfimprovement#motivationalspeech
https://t.me/LanguageStuff
Learning should be easy and enjoyable 😎👍
Rich Dad vs Poor Dad mindset 💸
Poor Dad: “Money comes when you work.”
Rich Dad: “Money comes when you build a system.”
The lesson:
Don’t only trade time for money.
Build assets, skills, and processes that pay you repeatedly.
Today’s action:
Pick ONE system to start:
• automate savings/investing
• create a digital product
• build a side business workflow
#RichDadPoorDad#money#wealth#mindset#financialfreedom#selfimprovement#books
How to Get Ahead of 99% of People (Starting Today)
2023-03-20 by Mark Manson
#markmanson#markmanson#selfimprovement#howtochangeyourlife#betterideas#selfimprovementtips#selfimprovementbooks
#YouTube#liked