The Python Oracle

Heroku app runs locally but gets H12 timeout error (uses a package)

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Track title: CC F Haydns String Quartet No 53 in D

--

Chapters
00:00 Question
02:13 Accepted answer (Score 14)
02:49 Thank you

--

Full question
https://stackoverflow.com/questions/1602...

Question links:
[Flask Mega-Tutorial]: http://blog.miguelgrinberg.com/post/the-...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #heroku #flask #gunicorn

#avk47



ACCEPTED ANSWER

Score 14


The issue is that run.py unguardedly calls app.run - this actually calls werkzeug.serving.run_simple which starts a sub-process to handle incoming requests ... which you don't want to do when running under gunicorn (since gunicorn will handle the process management for you).

Simply add an if __name__ == "__main__" guard before your app.run call and everything should work:

# run.py
if __name__ == "__main__":
    app.run()