Функция 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
📰 Wine 11.8 Brings Mono Engine Update and 22 Bug Fixes
Wine 11.8 updates Mono to version 11.1, improves MSXML and VBScript support, and fixes 22 bugs across games and Windows apps.
🔗 Source: https://linuxiac.com/wine-11-8-brings-mono-engine-update-and-22-bug-fixes/
#wine
Ancient factory exposes secrets of winemaking
A 1,500-year-old wine factory the size of a modern-day football field has been unearthed in Israel, showing how vintners met demand for high quality white wine popular throughout the ancient world.
#News#Reuters#Israel#Wine
Subscribe: http://smarturl.it/reuterssubscribe
Reuters brings you the latest business, finance and breaking news video from around the globe. Our reputation for accuracy and impartiality is unparalleled.
Get the latest news on: http://reuters.com/
Follow Reuters on Facebook: https://www.facebook.com/Reuters
Follow Reuters on Twitter: https://twitter.com/Reuters
Follow Reuters on Instagram: https://www.instagram.com/reuters/?hl=en
➖@reutersworldchannel➖
📰 Proton 11.0 Beta 2 Updates VKD3D-Proton
Following the release of Proton 11.0 Beta 1 from two weeks ago that updated against Wine 11.0, this heart to Valve's Steam Play is now out with a second beta release...
🔗 Source: https://www.phoronix.com/news/Proton-11.0-Beta-2
#proton#steam#wine
Early Roman women were forbidden to drink wine, and a husband who found his wife drinking was at liberty to kill her. The prohibition stemmed from a deeply patriarchal society that viewed women as weak and susceptible to vice, believing that wine could lead them to "inappropriate behavior" or "debauchery".
@googlefactss#alcohol#wine#history#nowyouknow