1 year ago
#371835
Alexey Kholodkov
Bypass gunicorn worker timeout for specific endpoint
I have Django (3.2.4) app running on Gunicorn (20.1.0) and that app have one heavy endpoint. This endpoint returns csv report which may be very big:
def _stream_serialized_data():
paginator = Paginator(MyModel.objects.filter(**filter), 5000)
for page in paginator.page_range:
yield from MySerializer(paginator.page(page).object_list, many=True).data
renderer = CSVStreamingRenderer()
return StreamingHttpResponse(
renderer.render(_stream_serialized_data(), renderer_context={"header": MySerializer.Meta.fields}),
content_type="text/csv",
headers={"Content-Disposition": 'attachment; filename="report.csv"'},
)
The problem is that report loading may be aborted by gunicorn worker timeout despite loading starts immediately and there is very small delay between chunks.
Is there a way to inform gunicorn that this worker is fine? May be call some function from _stream_serialized_data
loop to reset timeout.
I already found suggestions to increase timeout and to use gevent, but I don't want to do anything than affects other endpoints.
django
gunicorn
0 Answers
Your Answer