Heroku application launches locally, but receives H12 timeout error (uses package)

Similar questions were asked, but the H12 seems to be triggered by many things, and none of the answers apply here. I have already created python applications with heroku, but now I use the package structure for the Miguel Grinberg Flask Mega-Tutorial , and I can not understand what is wrong.

My application is python / Flask / SQLAlchemy with Heroku postgres database. The application works fully locally. When I click on Heroku, I get H12.

Here is my application structure:

rootappdirectory\ app\ static\ templates\ __init__.py views.py models.py run.py [plus flask / venv files] 

run.py looks like this:

 import os from flask import Flask from app import app app.run() 

And app / __ init__.py looks like this:

 (a bunch of imports) app = Flask(__name__) db = SQLAlchemy(app) login_manager = LoginManager() (a bunch of login_manager stuff) from app import views, models 

My Procfile web: gunicorn run:app file

I use heroku database locally and remotely. The application works fine on my local machine (0.0.0.0/10000). But when I click on the hero and launch the application, here are the logs:

 2013-04-15T06:50:27.165532+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path=/favicon.ico host=floating-driftwood-6203.herokuapp.com fwd="24.6.48.240" dyno=web.1 connect=1ms service=30007ms status=503 bytes=0 2013-04-15T06:50:34.908756+00:00 app[web.1]: 2013-04-15 06:50:34 [2] [CRITICAL] WORKER TIMEOUT (pid:65) 2013-04-15T06:50:34.914436+00:00 app[web.1]: 2013-04-15 06:50:34 [2] [CRITICAL] WORKER TIMEOUT (pid:65) 2013-04-15T06:50:34.918114+00:00 app[web.1]: 2013-04-15 06:50:34 [66] [INFO] Booting worker with pid: 66 2013-04-15T06:50:35.083182+00:00 app[web.1]: * Running on http://127.0.0.1:5000/ 2013-04-15T06:51:04.216671+00:00 app[web.1]: 2013-04-15 06:51:04 [2] [CRITICAL] WORKER TIMEOUT (pid:66) 2013-04-15T06:51:04.223440+00:00 app[web.1]: 2013-04-15 06:51:04 [2] [CRITICAL] WORKER TIMEOUT (pid:66) 2013-04-15T06:51:04.229350+00:00 app[web.1]: 2013-04-15 06:51:04 [67] [INFO] Booting worker with pid: 67 

I played with different options - at first I got a "connection in use" error, which I fixed by going to debug = False, but, frankly, I would rather debug = True! It seems that the problem is that my main application is not in the root directory?

Thanks in advance.

+3
source share
1 answer

The problem is that run.py unconditionally calls app.run - it actually calls werkzeug.serving.run_simple , which starts a subprocess to process incoming requests ... which you donโ€™t want to do when it starts with a gun (since it will process process management for you).

Just add guard if __name__ == "__main__" before calling app.run , and everything should work:

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

Source: https://habr.com/ru/post/959435/


All Articles