Функция 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
Another mining has appeared in Telegram, in this one we are farming the token $CUBE
🏆Start CUBE Mining
Entry price is - 39⭐️
The price may increase at any time to avoid the load!
You can also complete tasks for free and get entry!
Don't miss out! Get in among the first!
Link ➡️@Cubeapp_bot
We will follow the project and its development!
⭐️Buy stars for ton⭐️
#cube#ton
In Game ❓ CUBES has released a useful update — now you can unite with the whole clan and mine the pool!
❤️ Now, together with #TonEvents we farm cubes even more efficiently and divide the loot among everyone, in proportion to your contribution:
2.5% of the production goes to the development of the pool, 12.5% goes to the lucky person who gets the cube, and the remaining 85% is divided among all pool participants
⛏ Each of you can boost our pool, that is, add 1,000 drops to the boost, then the next level of the pool will open and farming will become even more profitable, especially after halving, so we need to collect 500,000 drops.
⚰️ After the intermediate drop from #CUBE, the hamsters “abandoned ship,” but real miners know that now is the time to farm.
👍 Therefore, we all join in and raise our pool to the top, because the next halving is just around the corner.
⚡️Boost | 🌐Twitter
В Telegram появился еще один майнинг, в нем мы фармим токен $CUBE
🏆Запустить Майнинг CUBE
Цена входа составляет — 19⭐️
Цену могут повысить в любой момент, дабы избежать нагрузки!
Также можно выполнить задания бесплатно и получить вход!
Не пропускаем! Залетаем в числе первых!
Ссылка ➡️@Cubeapp_bot
Будем следить за проектом и его развитием!
⭐️Купить звёзды за ton⭐️
#cube#ton
💎 Auto Text自动回复v5.9.4解锁高级版 46.2
♻️资源介绍:Auto Text(原Do It Later)是一款简洁好用的以后再做计划程序应用,有了 Do It Later Pro 即使您在睡觉、忙碌或不在手机旁时,也可以给某人你发送短信(SMS)
⬇️本地下载
🔔标签:#安卓软件#PDF#合并#拆分#Cube#Page