TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #401 · 15 дек.

Функция asyncio.wait() это еще один способ вызвать множество асинхронных задач. Она работает в нескольких режимах. 1. Самый простой - ждем завершения всех задач async def main(): tasks = [asyncio.create_task(do_it(i)) for i in range(10)] done, pending = await asyncio.wait( tasks, return_when=asyncio.ALL_COMPLETED ) for task in done: try: print(task.result()) except Exception as e: print(e) Очень похоже на gather, но работает не так. ▫️возвращает не результаты, а два сета с объектами Task у которых можно забрать результат через task.result() если они в списке done ▫️не гарантирует порядок результатов так как оба объекта это set ▫️не выбрасывает исключение когда оно появляется, а сохраняет его в Task. Исключение появится когда попробуете забрать резултьтат. 2. Ждем завершения первой задачи, даже если там ошибка. async def main(): tasks = [asyncio.create_task(do_it(i)) for i in range(3)] done, pending = await asyncio.wait( tasks, return_when=asyncio.FIRST_COMPLETED ) # в done может быть несколько задач! for task in done: try: print(task.result()) except Exception as e: print(f"Fail: {e}") # Оставшиеся задачи в pending, как правило, нужно отменить, иначе они будут продолжать работать for task in pending: task.cancel() В сете done будут таски которые успели завершится, причем как успешно так и нет. 3. До первой ошибки. Тоже самое, но с аргументом FIRST_EXCEPTION done, pending = await asyncio.wait( tasks, return_when=asyncio.FIRST_EXCEPTION ) Функция завершается как только первая задача упадет с ошибкой. Учтите, что в любом случае done вы можете обранужить несколько задач, как с ошибками так и успешные. ↗️ Полный листинг примеров здесь #async

Hashtags

Резултати

Пронајдени 160 слични објави

Пребарај: #wildlife

当前筛选 #wildlife清除筛选
Amazing Geography 🌍

@amazingeo · Post #648 · 26.02.2026 г., 20:31

🌍 In Singapore, “eco-bridges” covered in greenery let wild animals safely cross over busy highways. These living bridges reconnect habitats split by urban growth, reducing roadkill. ✨ #nature⚡#urban⚡#wildlife⚡#geography⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

RTDocumentary

@rtdocumentary · Post #867 · 05.06.2022 г., 11:59

June 5 is World Environment Day. On this day, we want to tell you a story from Zimbabwe, where hundreds of elephants are killed by poachers. Roxy Danckwerts founded the Wild is Life wildlife sanctuary at her family farm. She and her staff nurse orphaned baby elephants. They wouldn’t be able to survive in the wild but get a second chance at Roxy’s sanctuary. ‘When we have a new baby, we will often hang a blanket, and the baby will go into there thinking it’s the shape of the mother and put his head up to suckle,’ says Roxy. Do these infants have an opportunity to return to the wild? Watch the clip and documentary When an Elephant Smilesto find out. #Zimbabwe#wildlife#nature Follow: https://t.me/rtdocumentary

123•••10•••1314
ПретходнаСтраница 1 од 14Следна