* Fixed tasks cancellation on app shutdown

This commit is contained in:
Phil Zhitnikov 2024-08-05 00:01:55 +04:00
parent 095896d847
commit b387604b25

View File

@ -25,12 +25,13 @@ async def startup_event():
@application.on_event("shutdown")
async def shutdown_event():
async with application.state.tasks_lock:
for task in application.state.tasks.values():
for task_list in application.state.tasks.values():
for task in task_list:
try:
task.cancel()
except asyncio.CancelledError:
pass
await asyncio.gather(*application.state.tasks.values(), return_exceptions=True)
application.state.tasks.clear()