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

Резултати

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

Пребарај: #butterflies

当前筛选 #butterflies清除筛选
Interesting Planet 🌍

@interesting_planet_facts · Post #1129 · 14.12.2025 г., 18:11

🌎 Spectacular animal migrations include the annual journey of monarch butterflies, which travel up to 4,800 kilometers from Canada and the U.S. to central Mexico. These butterflies navigate using a combination of environmental cues and an internal sun compass in their antennae. ✨ #migration⚡#butterflies⚡#nature 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1388 · 29.04.2026 г., 12:11

🌎 Monarch butterflies complete a multigenerational migration from Canada to central Mexico, traveling up to 4,500 kilometers. No single butterfly makes the entire round trip; several generations are born and die along the way. ✨ #butterflies⚡#migration⚡#insects 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1282 · 08.02.2026 г., 22:11

🌎 Each year, monarch butterflies migrate up to 4,800 kilometers from Canada and the northern United States to overwinter in central Mexico. Clusters of millions gather on oyamel fir trees, using environmental cues like the angle of sunlight to navigate. ✨ #migration⚡#butterflies⚡#insects 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #756 · 15.09.2025 г., 18:22

🌎 Monarch butterflies in North America complete one of the longest insect migrations, traveling up to 4,800 kilometers from Canada and the U.S. to central Mexico. Each fall, millions gather in mountain forests, forming dense colonies that help them survive winter’s cold. ✨ #butterflies⚡#migration⚡#insects 👉subscribe Interesting Planet ​

Interesting Planet 🌍

@interesting_planet_facts · Post #549 · 12.08.2025 г., 20:22

🌎 Some butterflies taste with their feet! Tiny sensors on their legs let them “sample” leaves, ensuring they lay eggs only on the best plants for their caterpillars. ✨ #butterflies⚡#senses⚡#nature 👉subscribe Interesting Planet

12
ПретходнаСтраница 1 од 2Следна