* Fixed tasks cancellation on app shutdown
This commit is contained in:
parent
095896d847
commit
b387604b25
|
|
@ -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():
|
||||
try:
|
||||
task.cancel()
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
await asyncio.gather(*application.state.tasks.values(), return_exceptions=True)
|
||||
for task_list in application.state.tasks.values():
|
||||
for task in task_list:
|
||||
try:
|
||||
task.cancel()
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
|
||||
application.state.tasks.clear()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user