2

I have a simple Flask app that I'm trying to deploy to Heroku, but I'm facing an Application Error and the logs seem to indicate that the app is stuck in some sort of restarting loop. I think there is a problem with my Procfile or run.py but I can't figure out what. Here are the Heroku logs:

2014-07-13T03:02:24.579923+00:00 app[web.1]:  * Running on http://127.0.0.1:5000/
2014-07-13T03:02:24.580216+00:00 app[web.1]:  * Restarting with reloader
2014-07-13T03:02:29.941158+00:00 app[web.1]: /app/app/mechanize_boilerplate.py:13: UserWarning: gzip transfer encoding is experimental!
2014-07-13T03:02:29.941168+00:00 app[web.1]:   br.set_handle_gzip(True)
2014-07-13T03:02:29.955461+00:00 app[web.1]:  * Running on http://127.0.0.1:5000/
2014-07-13T03:02:29.955738+00:00 app[web.1]:  * Restarting with reloader
2014-07-13T03:02:35.300236+00:00 app[web.1]:   br.set_handle_gzip(True)
2014-07-13T03:02:35.300231+00:00 app[web.1]: /app/app/mechanize_boilerplate.py:13: UserWarning: gzip transfer encoding is experimental!
2014-07-13T03:02:35.314821+00:00 app[web.1]:  * Running on http://127.0.0.1:5000/
2014-07-13T03:02:35.315107+00:00 app[web.1]:  * Restarting with reloader
...

Here is my current project structure:

/myapplication
    Procfile
    run.py
    requirements.txt
    /app
        __init__.py
        views.py
        mechanize_boilerplate.py
        /static
        /templates

Here is my Procfile

web: gunicorn run:app

Here is run.py

#!flask/bin/python
from app import app
app.run(debug = True)

Here is init.py

from flask import Flask

app = Flask(__name__)
from app import views

From there views.py runs and is pretty classic. I've seen a few similar questions and tried playing with my Procfile but couldn't get it work, all I managed to do was crashing the app. Any suggestions?

Community
  • 1
  • 1
Bnjii
  • 111
  • 8

1 Answers1

2

The problem is that your run.py runs your application when gunicorn imports it. You only want that to happen when you execute it.

#!flask/bin/python
from app import app
if __name__ == '__main__':
    app.run(debug = True)
dirn
  • 19,454
  • 5
  • 69
  • 74
  • Thanks a lot! That didn't work immediately but I changed my `run.py` to: `#!flask/bin/python from app import app if __name__ == '__main__': app.run()` And that fixed it! – Bnjii Jul 13 '14 at 16:47
  • Sorry, yeah, that's what I mean. I copied the code from the wrong file above. I'll fix the answer to make it cleared to people in the future. – dirn Jul 13 '14 at 17:53