I have a Flask app that runs fine on local, but when I push to Heroku I get the error message:
* Running on http://127.0.0.1:5000/
[INFO] Starting gunicorn 18.0
[ERROR] Connection in use: ('0.0.0.0', 8163)
I tried the solution in this question, where gunicorn and werkzeug were fighting with each other, but adding a __name__ == "__main__"
block to my master application file (run.py
) didn't solve my error.
This SO post suggested making sure my processes were all cleaned up. I did that but it still didn't work, so I actually deleted my entire heroku app and repushed and it still gives the same error.
My run.py
file looks like:
#!pl_env/bin/python
from app import app
if __name__ == "__main__":
app.run(debug=True, port=33507)
# [33507 is the Flask port on Heroku]
And my Procfile
is:
web: gunicorn run:app
The __init__.py
file in app is:
from flask import Flask
import os
from flask.ext.login import LoginManager
app = Flask(__name__)
app.config.from_object('config')
lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'
from app import views
Views has the meaty logic of the app in it, but I don't think there's anything in there that would mess with gunicorn. Here's the views.py imports just in case:
from flask import Flask, render_template, flash, redirect
from flask.ext.login import login_required, login_user
from app import app, lm
from forms import LoginForm
I am definitely at a loss as to where to look now to figure out this connection error. Any thoughts on why it seems to think I'm already using 0.0.0.0
?
Thank you
Monica
EDIT: I ran the app locally using foreman start
and it worked cleanly in 0.0.0.0:5000
, so I think I'm having a Heroku problem
EDIT2: I intentionally broke my view flow -- made an internal infinite reference -- and pushed it to see what would happen. I got the expected error logs, undid it, and pushed the rollback, and now it's working. I have absolutely no idea why that should work, except maybe that breaking it in an expected way flushed my gunicorn connections. If anyone has any explanations for this mystery, I would love them.