Closed Vedant-R closed 2 years ago
Yes...
@app.after_server_stop
async def cleanup(app: Sanic, _):
for task in asyncio.all_tasks():
if task is not asyncio.current_task():
while not task.done():
await task
app.purge_tasks
is meant to be used to just cleanup after tasks that have already run to completion.
If you are on the latest version of Sanic (which I am assuming you are since you brought up purge_tasks
, you have another option.
The above snippet is a sort of graceful shutdown. But, Sanic 21.12 will do this for you for any NAMED tasks.
So, if you did app.add_task(something, name="hello")
, then Sanic will track that task for you and clean it up.
v22.3 will probably take it one step further and cleanup all tasks. But, I am still working on that.
Thanks for the info @ahopkins I am using Sanic version 21.6.0.
I understood the logic here.
For every test I run, my tests pass but I get the following error:
@ahopkins Is there a way to purge tasks before app/server stops to avoid above warnings?