Django file download timeout






















Collectives on Stack Overflow. Learn more. Gunicorn timeout during file download Ask Question. Asked 2 years, 5 months ago.

Active 1 year, 8 months ago. Viewed 3k times. Add a comment. Active Oldest Votes. The problem is your gunicorn command. But what if the file take more than 5 minutes? Is there a way to avoid the timeout during a streaming http connection? To group by different period use the following setting:. Mar 8, Apr 1, Dec 14, Nov 10, Sep 6, Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Download the file for your platform. If you're not sure which to choose, learn more about installing packages. Warning Some features may not work without JavaScript. Please try enabling it if you encounter problems. Search PyPI Search. Latest version Released: Jul 9, Django global response timeout middleware.

Navigation Project description Release history Download files. If you're returning something that you need to format all at once, for example if you're using something like wkhtmltopdf to generate a pdf file after you're done, then it's not as easy. What you can do in that case is, use StreamingHttpReponse along with a generator function to generate your report into a temporary file, instead of back to the browser.

But as you are doing this, yield HTML snippets back to the browser which lets the user know the progress, eg:. When your user fetches this view, they will see the progress of the report as it comes along.

At the end, you're sending the javacript which redirect the browser to the other view you will have to write which returns the response containing the finished file. When the browser gets this javacript, if the view returning the tempfile is setting the response Content-Disposition as an attachment before returning it, eg:. For cleanup, you'll need a cron job regardless.. Sometimes things don't work out So you could just clean up files older than let's say 1 hour.

For a lot of systems this is acceptable. So, open your tempfile.. Then return your response. As soon as the response has finished sending, the space used by the file will be freed.

PS: I should add.. You can always increase your server time outs but it would still, IMO, give you a bad user experience if the user has to sit watching the browser just spin. Doing this on a background task is the only way to do it right.



0コメント

  • 1000 / 1000