Terminate background task

Scenario: The web asks the sanic app to start a time-consuming background task through an ajax request. After a few seconds, the web asks the sanic app to terminate the background task just started through an ajax request.
How can I implement it in sanic app?

There isn’t a particular Sanic-centric way to handle this. Once a task is started, Sanic itself does not track tasks. I’ve thought about adding an API for that, but I had not seen interest.

You could loop through all_tasks for the one you want: Coroutines and Tasks — Python 3.9.6 documentation

Thanks for your reply. :grinning_face_with_smiling_eyes: :grinning_face_with_smiling_eyes:

1 Like