Отдельно разберём TaskGroup, который пришел на замену gather в Python 3.11.
Ключевые отличия
▫️create_task() возвращает объект asyncio.Task, у которого есть соответствюущие методы управления. То есть у нас больше контроля
▫️это контекстный менеджер, который гарантирует что все таски будут остановлены по выходу из контекста
▫️ошибка автоматически отменяет незавершенные задачи,
▫️except* передает нам ExceptionGroup, в котором каждую ошибку можно обработать отдельно
import asyncio
import random
async def do_it() -> str:
if random.random() < 0.1:
raise ValueError('Oops')
delay = random.uniform(0.5, 1.5)
await asyncio.sleep(delay)
return delay
async def main():
try:
async with asyncio.TaskGroup() as tg:
for _ in range(10):
tasks.append(tg.create_task(do_it()))
for t in tasks:
print(t.result())
except *ValueError as e:
for err in e.exceptions:
print(err)
asyncio.run(main())
Рекомендую изучить страницу Coroutines and Tasks из документации, где представлено больше интересных примеров и механизмов
- таймауты
- отмена задач
- создание задач из другого потока
#async
Viral Haemorrhagic Fevers #VHFs are a group of illnesses caused by viruses that damage blood vessels and can cause severe bleeding.
Our national guideline on #InfectionPreventionandControl for #VHFs is designed as a major reference for anyone involved in the care and management of #VHFs cases.
🔗Download and read via
https://ncdc.gov.ng/themes/common/docs/protocols/111_1579986179.pdf
Viral Haemorrhagic Fevers #VHFs are a group of illnesses caused by viruses that damage blood vessels and can cause severe bleeding.
Our national guideline on #InfectionPreventionandControl for #VHFs is designed as a major reference for anyone involved in the care and management of #VHFs cases.
🔗Download and read via
https://ncdc.gov.ng/themes/common/docs/protocols/111_1579986179.pdf
Viral Haemorrhagic Fevers such as #LassaFever spread mainly from person to person through direct & indirect contact.
When properly done, #HandHygiene is very important to reduce the risk of healthcare workers' infection.
Our #IPC guidelines for #VHFs⬇️
https://ncdc.gov.ng/themes/common/docs/protocols/111_1579986179.pdf
Viral hemorrhagic fevers #VHFs such as #LassaFever affect multiple organ systems in the body and may be accompanied by bleeding.
Download and share our National Guideline on #IPC for #VHF for measures required in the management of VHFs
🔗
https://ncdc.gov.ng/themes/common/docs/protocols/111_1579986179.pdf
Viral hemorrhagic fevers #VHFs are a group of infectious diseases that affect multiple organ systems in the body and may be accompanied by bleeding.
What are the #InfectionPreventionandControl practices that need to be in place in the management of VHFs?
🔗Download our National Guideline on #IPC for #VHF
https://ncdc.gov.ng/themes/common/docs/protocols/111_1579986179.pdf
Common Viral Haemorrhagic Fevers #VHFs include #LassaFever, #EbolaVirusDisease, #YellowFever, #DengueFever, #MarburgFever and #CrimeanCongoHaemorrhagicFever.
What are the #InfectionPreventionandControl practices that need to be in place in the management of VHFs?
🔗Download our National Guideline on #IPC for #VHF
https://ncdc.gov.ng/themes/common/docs/protocols/111_1579986179.pdf