* 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")
|
@application.on_event("shutdown")
|
||||||
async def shutdown_event():
|
async def shutdown_event():
|
||||||
async with application.state.tasks_lock:
|
async with application.state.tasks_lock:
|
||||||
for task in application.state.tasks.values():
|
for task_list in application.state.tasks.values():
|
||||||
try:
|
for task in task_list:
|
||||||
task.cancel()
|
try:
|
||||||
except asyncio.CancelledError:
|
task.cancel()
|
||||||
pass
|
except asyncio.CancelledError:
|
||||||
await asyncio.gather(*application.state.tasks.values(), return_exceptions=True)
|
pass
|
||||||
|
|
||||||
application.state.tasks.clear()
|
application.state.tasks.clear()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user