I want to abort a request to an API which takes longer than 5 seconds. I know the client-side code can have a timeout of 5 seconds and that will ensure it doesn't wait any longer than that to get a response, but the Django server would still be processing the request even though the client won't be receiving it at the end. As far as I know, even if I configure this on nginx or gunicorn, those will still act as clients for the Django server app and the same problem will occur - that nginx will not wait for more than 5 seconds, but Django will continue processing the request.
Is there any way I can somehow abort this request processing in Django (application server code level) itself?
For context on the specific use case: This API parses a file and we have a size limit of 5 MB on that file. Even then, for some reason, sometimes, the file parsing takes more than 20-30 seconds, which is why we want to abort the request for this API if it exceeds a certain threshold.