我正在尝试将项目https://github.com/kc1/flask-huey-example部署到heroku,以允许使用任务队列和烧瓶。项目布局如上所述。您还可以查看我更新的github存储库。该项目在Windows本地正常运行(本地未使用gunicorn)。
我的个人档案:
web: gunicorn run_app:app
worker: python /app/.heroku/python/bin/huey_consumer run_huey.huey
我以前遇到错误Failed to find application object 'app' in 'run_app'。我试图通过将run_app.py更改为以下内容来解决此问题:
from app import create_app, config
if __name__ == '__main__':
import logging
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
app = create_app()
app.run(host='localhost', port=6060, debug=True)
else:
app = create_app()
app.run(debug=False)
不幸的是,现在当我按下heroku时,我看到了:
2018-08-16T16:37:59.253114+00:00 app[web.1]: [2018-08-16 16:37:59 +0000] [8] [ERROR] Exception in worker process
2018-08-16T16:37:59.253118+00:00 app[web.1]: Traceback (most recent call last):
2018-08-16T16:37:59.253121+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2018-08-16T16:37:59.253123+00:00 app[web.1]: worker.init_process()
2018-08-16T16:37:59.253124+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
2018-08-16T16:37:59.253126+00:00 app[web.1]: self.load_wsgi()
2018-08-16T16:37:59.253128+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2018-08-16T16:37:59.253130+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2018-08-16T16:37:59.253132+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2018-08-16T16:37:59.253133+00:00 app[web.1]: self.callable = self.load()
2018-08-16T16:37:59.253135+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2018-08-16T16:37:59.253137+00:00 app[web.1]: return self.load_wsgiapp()
2018-08-16T16:37:59.253139+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2018-08-16T16:37:59.253140+00:00 app[web.1]: return util.import_app(self.app_uri)
2018-08-16T16:37:59.253142+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
2018-08-16T16:37:59.253144+00:00 app[web.1]: __import__(module)
2018-08-16T16:37:59.253146+00:00 app[web.1]: File "/app/run_app.py", line 21, in <module>
2018-08-16T16:37:59.253148+00:00 app[web.1]: app.run(debug=False)
2018-08-16T16:37:59.253149+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 841, in run
2018-08-16T16:37:59.253151+00:00 app[web.1]: run_simple(host, port, self, **options)
2018-08-16T16:37:59.253153+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/serving.py", line 814, in run_simple
2018-08-16T16:37:59.253155+00:00 app[web.1]: inner()
2018-08-16T16:37:59.253157+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/serving.py", line 774, in inner
2018-08-16T16:37:59.253159+00:00 app[web.1]: fd=fd)
2018-08-16T16:37:59.253161+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/serving.py", line 666, in make_server
2018-08-16T16:37:59.253162+00:00 app[web.1]: passthrough_errors, ssl_context, fd=fd)
2018-08-16T16:37:59.253164+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/serving.py", line 577, in __init__
2018-08-16T16:37:59.253165+00:00 app[web.1]: self.address_family), handler)
2018-08-16T16:37:59.253167+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/socketserver.py", line 453, in __init__
2018-08-16T16:37:59.253169+00:00 app[web.1]: self.server_bind()
2018-08-16T16:37:59.253171+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/http/server.py", line 136, in server_bind
2018-08-16T16:37:59.253173+00:00 app[web.1]: socketserver.TCPServer.server_bind(self)
2018-08-16T16:37:59.253181+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/socketserver.py", line 467, in server_bind
2018-08-16T16:37:59.253183+00:00 app[web.1]: self.socket.bind(self.server_address)
我该如何解决?
答案 0 :(得分:0)
您试图将应用程序绑定到的端口已被另一个应用程序使用。关闭另一个应用程序,然后重新部署
答案 1 :(得分:0)
尝试在 Heroku 上运行 Flask 应用程序时遇到了同样的错误,并通过删除了
app.run
完全来自我的应用程序文件的声明(我的应用程序文件名为 app.py),例如您的 run_app.py。
我的档案:
web: gunicorn -b 0.0.0.0:$PORT app:app
当我想在本地运行应用程序时,我在终端(MacOS zsh)中运行
FLASK_ENV=development flask run