A django project I work on allows a user to preview a document made on our site before downloading it. The process takes some time on the backend which is why we allow the user to cancel the operation on the frontend. But even after the user cancels the process, it still keeps running on the server wasting time and compute. We use a simple django-rest-framework api function with no socket connection or anything asynchronous that allows the frontend to track the progress of the task.
I would like to know if there is some way we can abort the function execution on the backend if the user decides to cancel the operation on the frontend.
I'd share any code but I don't think it'll be useful because the function just prepares the document and then sends it.