简体   繁体   中英

Deploying Flask app to Heroku stuck in restarting loop

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM