Функция 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
FJORDS(峡湾) 8K 60FPS
Although a sought-after destination in the summer, the Norwegian fjords lay mostly empty in the winter time. However, this time of year is no less magical. This video aim to show this magic, all in glorious 8K resolutions at 60 fps.
挪威峡湾虽然是夏季的热门目的地,但在冬季时空无一人,在一年中的这个时间的景色同样非常不可思议。此视频旨在以60 fps的出色8K分辨率显示这种魔力。
- 作者: Morten Rustad
- https://youtu.be/0pmvuKzBIqM
频道: @View_4k#8k
Hawaii in 8K ULTRA HD - Paradise of North America (60fps)
This videos you can use for learn Nature, about place, River, Country, City, etc with Ultra-HD resolution.
- 原视频: https://youtu.be/PF1EAtMswPo
- 画质(上面链接): 8K60P
- 作者: 8K World
统计: @View_4k#4k#8k
From Darkness To Light
From Darkness To Light is an 8k Time-Lapse film shot by storm chaser Ty Schmitt. All the clips in the film were captured on the Great Plains during the 2019 spring storm season. Ty traveled over 30,000 miles in 3 months chasing Mother Nature's most intense moments.
All images were shot on a Nikon D850, and edited in LRTimelapse, After Effects, and Premiere Pro.
- 原视频: https://youtu.be/MlIXpZFTBP4
- 画质(上面链接): 8K
- 作者: Ty Schmitt
统计: @View_4k#4k#8k
Hawaii in 8K ULTRA HD - Paradise of North America (60fps)
This videos you can use for learn Nature, about place, River, Country, City, etc with Ultra-HD resolution.
- 原视频: https://youtu.be/PF1EAtMswPo
- 画质(上面链接): 8K60P
- 作者: 8K World
统计: @View_4k#4k#8k
From Darkness To Light
From Darkness To Light is an 8k Time-Lapse film shot by storm chaser Ty Schmitt. All the clips in the film were captured on the Great Plains during the 2019 spring storm season. Ty traveled over 30,000 miles in 3 months chasing Mother Nature's most intense moments.
All images were shot on a Nikon D850, and edited in LRTimelapse, After Effects, and Premiere Pro.
- 原视频: https://youtu.be/MlIXpZFTBP4
- 画质(上面链接): 8K
- 作者: Ty Schmitt
统计: @View_4k#4k#8k
Frankfurt
Frankfurt is a city of great diversity. It is a metropolis of banks and big business shows and shopping on the one side, culture and traditions on the other.
- 原视频: https://youtu.be/UaveL8lp_ws
- 画质(上面链接): 8K
- 作者: Cities in 4K
统计: @View_4k#4k#8k
FJORDS(峡湾) 8K 60FPS
Although a sought-after destination in the summer, the Norwegian fjords lay mostly empty in the winter time. However, this time of year is no less magical. This video aim to show this magic, all in glorious 8K resolutions at 60 fps.
挪威峡湾虽然是夏季的热门目的地,但在冬季时空无一人,在一年中的这个时间的景色同样非常不可思议。此视频旨在以60 fps的出色8K分辨率显示这种魔力。
- 作者: Morten Rustad
- https://youtu.be/0pmvuKzBIqM
频道: @V1_BLOG#8k#view
TelegramUltraPrivateChannel #0042
My old designs in 8 Colors
>> FOR <<
#iPhone14
#iPadAir5
#8K#Desktop
----------------------
Prod. By@Hk3ToN
----------------------