Функция 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
Our #LassaFever situation report for week 1, 2025 has been published.
54 cases have been confirmed and 10 deaths have been recorded across 6 states in Nigeria.
🔗Download, read, and share via https://ncdc.gov.ng/ncdc.gov.ng/themes/common/files/sitreps/1bded1685f8dc4961a169a274be138c2.pdf
Our #LassaFever situation reports for weeks 42, 2024 have been published.
The weekly report provides a summary of the #LassaFever epidemiological situation and response activities in Nigeria.
🔗Download, read, and share via
https://ncdc.gov.ng/diseases/sitreps/?cat=5&name=An%20update%20of%20Lassa%20fever%20outbreak%20in%20Nigeria
Our #LassaFever situation report for week 40, 2024 has been published.
1025 cases have been confirmed and 174 deaths have been recorded across 28 states in Nigeria.
🔗Download, read, and share via
https://ncdc.gov.ng/diseases/sitreps/?cat=5&name=An%20update%20of%20Lassa%20fever%20outbreak%20in%20Nigeria
Our latest #LassaFever situation report shows that 982 confirmed cases and 168 deaths have been recorded in 2024.
This loss of lives is not just a number but a significant loss of a family member, friend, colleague or a seasoned healthcare worker
CEPI vaccines writes on the critical need for a #LassaFever vaccine to control this disease.
🔗
https://cepi.net/lassa-vaccine-urgently-needed-save-thousands-lives
Situation report: https://ncdc.gov.ng/diseases/sitreps/?cat=5&name=An%20update%20of%20Lassa%20fever%20outbreak%20in%20Nigeria
We have published our latest #LassaFever epidemiology data.
Here you can find a summary of all the latest figures in our weekly infographic.🔽
The full report can be accessed via
🔗https://ncdc.gov.ng/diseases/sitreps/?cat=5&name=An%20update%20of%20Lassa%20fever%20outbreak%20in%20Nigeria
Our #LassaFever situation report for week 32, 2024 has been published.
The weekly report provides a summary of the #LassaFever epidemiological situation and response activities in Nigeria.
🔗Download, read, and share via
https://ncdc.gov.ng/diseases/sitreps/?cat=5&name=An%20update%20of%20Lassa%20fever%20outbreak%20in%20Nigeria
Our #LassaFever situation report for week 30, 2024 has been published.
The weekly report provides a summary of the #LassaFever epidemiological situation and response activities in Nigeria.
🔗Download, read, and share via
https://ncdc.gov.ng/diseases/sitreps/?cat=5&name=An%20update%20of%20Lassa%20fever%20outbreak%20in%20Nigeria
Our #LassaFever situation reports for weeks 28 and 29, 2024 have been published.
The weekly report provides a summary of the #LassaFever epidemiological situation and response activities in Nigeria.
🔗Download, read, and share via
https://ncdc.gov.ng/diseases/sitreps/?cat=5&name=An%20update%20of%20Lassa%20fever%20outbreak%20in%20Nigeria
Our #LassaFever situation report for week 25, 2024 has been published.
The weekly report provides a summary of the #LassaFever epidemiological situation and response activities in Nigeria.
🔗Download, read, and share via
https://ncdc.gov.ng/diseases/sitreps/?cat=5&name=An%20update%20of%20Lassa%20fever%20outbreak%20in%20Nigeria
Our #LassaFever situation report for week 24, 2024 has been published.
The weekly report provides a summary of the #LassaFever epidemiological situation and response activities in Nigeria.
🔗Download, read, and share via
https://ncdc.gov.ng/diseases/sitreps/?cat=5&name=An%20update%20of%20Lassa%20fever%20outbreak%20in%20Nigeria
Our #LassaFever situation report for week 23, 2024 has been published.
The weekly report provides a summary of the #LassaFever epidemiological situation and response activities in Nigeria.
🔗Download, read, and share via
https://ncdc.gov.ng/diseases/sitreps/?cat=5&name=An%20update%20of%20Lassa%20fever%20outbreak%20in%20Nigeria
Our #LassaFever situation report for week 21, 2024 has been published.
The weekly report provides a summary of the #LassaFever epidemiological situation and response activities in Nigeria.
🔗Download, read, and share via
https://ncdc.gov.ng/diseases/sitreps/?cat=5&name=An%20update%20of%20Lassa%20fever%20outbreak%20in%20Nigeria