I want to set a timeout in the view, if the code execution in the view exceeds the timeout
# urls.py
url(r'^test-api/$', test_api_view)
# views.py
from rest_framework import status
from rest_framework.response import Response
def test_api_view(request):
timeout=10
data = someMethod()
if xxx: # Call some_method() for more than 10 seconds, and the method call may not end
return Response({"error": "Timeout"})
else:
return Response(data)