heroku gunicorn / Flask 应用程序错误 "Exception in worker process"

heroku gunicorn / Flask app error "Exception in worker process"

我们将应用程序部署到 heroku (git heroku push); 它使用 gunicorn 和其他要求(请参阅下面的 requirements.txt)

heroku logs --tail 的输出包含此消息,其中包括 "Exception in worker process..."

我们尝试了不同版本的 Python,我们尝试了不同版本的库,我们尝试重命名我们的 app.py 文件/应用程序变量——但仍然是错误,没有提到我们的堆栈跟踪中的代码...

2019-10-23T23:47:16.828218+00:00 app[web.1]: [2019-10-23 23:47:16 +0000] [4] [INFO] Listening at: http://0.0.0.0:58467 (4)
2019-10-23T23:47:16.82839+00:00 app[web.1]: [2019-10-23 23:47:16 +0000] [4] [INFO] Using worker: sync
2019-10-23T23:47:16.834106+00:00 app[web.1]: [2019-10-23 23:47:16 +0000] [10] [INFO] Booting worker with pid: 10
2019-10-23T23:47:16.842032+00:00 app[web.1]: [2019-10-23 23:47:16 +0000] [10] [ERROR] Exception in worker process
2019-10-23T23:47:16.842035+00:00 app[web.1]: Traceback (most recent call last):
2019-10-23T23:47:16.842038+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-10-23T23:47:16.84204+00:00 app[web.1]: worker.init_process()
2019-10-23T23:47:16.842042+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
2019-10-23T23:47:16.842044+00:00 app[web.1]: self.load_wsgi()
2019-10-23T23:47:16.842046+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2019-10-23T23:47:16.842048+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-10-23T23:47:16.84205+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-10-23T23:47:16.842052+00:00 app[web.1]: self.callable = self.load()
2019-10-23T23:47:16.842054+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2019-10-23T23:47:16.842056+00:00 app[web.1]: return self.load_wsgiapp()
2019-10-23T23:47:16.842057+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2019-10-23T23:47:16.842059+00:00 app[web.1]: return util.import_app(self.app_uri)

我们的 heroku 配置文件包括: 简介:

web: gunicorn app: app

runtime.txt

python-3.6.9

requirements.txt:

certifi==2019.9.11
chardet==3.0.4
Click==7.0
dnspython==1.16.0
Flask==1.1.1
Flask-PyMongo==2.3.0
gunicorn==19.9.0
idna==2.8
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
numpy==1.17.2
pandas==0.25.1
pymongo==3.9.0
python-dateutil==2.8.0
pytz==2019.3
requests==2.22.0
six==1.12.0
ujson==1.35
urllib3==1.25.6
Werkzeug==0.16.0
wincertstore==0.2

我的procfile是错误的,应该不是 app: app之间的space。 gunicorn documentation基本用法:

$ gunicorn [OPTIONS] APP_MODULE

Where APP_MODULE is of the pattern $(MODULE_NAME):$(VARIABLE_NAME).

错误:

web: gunicorn app: app

:

web: gunicorn app:app

我混淆了 heroku Procfile syntaxgunicorn 命令;

  • heroku Procfile syntax "process type": "command" 组合中指定 web 后允许 space;例如web: gunicorn ...
  • gunicorn 命令 不允许 space;例如app:app