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

Viewed 8184

We deploy our app to heroku (git heroku push); It uses gunicorn and other requirements (see below for requirements.txt)

The output of heroku logs --tail include this message, including "Exception in worker process..."

We tried different versions of Python, we tried different versions of our libraries , and we tried renaming our app.py file / app variable -- but still the error, which does not mention our code in the stack trace...

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)

Our heroku config files include: Procfile:

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
1 Answers

My procfile was wrong, there should not be a space between app: app. The gunicorn documentation basic usage:

$ gunicorn [OPTIONS] APP_MODULE

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

Wrong:

web: gunicorn app: app

Right:

web: gunicorn app:app

I was confusing the heroku Procfile syntax with the gunicorn command;

  • The heroku Procfile syntax does allow a space after specifying the web in the "process type": "command" combination; e.g. web: gunicorn ...
  • Whereas the gunicorn command does not allow a space; e.g. app:app
Related