问题
I'm building a web app using Flask and hosting it on Heroku. My app scrapes the web—so it can take anywhere from a few seconds to 20 minutes, depending on the search criteria. When I try to run bigger requests, the application times out after the default 30 seconds. Does anyone know how to increase the timeout length? I've tried changing the Profile from this:
web: gunicorn myapp:app --log-file=-
to this:
web: gunicorn myapp:app --timeout 1200
but got nowhere.
But when I changed it to
web: gunicorn myapp:app --timeout 5
it timed out at 5 seconds
回答1:
Heroku has a limit of 30 sec
for any request to complete. If the request takes more than 30s
then it leads to H12 error
.
So, in your case you can't set
web: gunicorn myapp:app --timeout 1200
Ref: https://devcenter.heroku.com/articles/python-gunicorn#worker-timeouts and https://devcenter.heroku.com/articles/limits#http-timeouts
来源:https://stackoverflow.com/questions/27233134/flask-python-increase-timeout-length-on-heroku-app