26

I've installed gunicorn inside my virtualenv.

From this directory:

manage.py
/onbytes/wsgi.py

I run the following:

gunicorn onbytes.wsgi:application

And I get the following error:

Traceback (most recent call last):
  File "/home/ymorin007/.virtualenvs/onbytes.com/bin/gunicorn", line 9, in <module>
    load_entry_point('gunicorn==19.0.0', 'console_scripts', 'gunicorn')()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 166, in run
    super(Application, self).run()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
    Arbiter(self).run()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 169, in run
    self.manage_workers()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
    self.spawn_workers()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 537, in spawn_workers
    time.sleep(0.1 * random.random())
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
    self.reap_workers()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers
    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

running gunicorn onbytes.wsgi:application --preload will get me this error:

Traceback (most recent call last):
  File "/home/ymorin007/.virtualenvs/onbytes.com/bin/gunicorn", line 9, in <module>
    load_entry_point('gunicorn==19.0.0', 'console_scripts', 'gunicorn')()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 166, in run
    super(Application, self).run()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
    Arbiter(self).run()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 57, in __init__
    self.setup(app)
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 113, in setup
    self.app.wsgi()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 66, in wsgi
    self.callable = self.load()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/ymorin007/.virtualenvs/onbytes.com/local/lib/python2.7/site-packages/gunicorn/util.py", line 356, in import_app
    __import__(module)
  File "/home/ymorin007/sites/onbytes.com/src/onbytes/wsgi.py", line 8, in <module>
    from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi
Yannick
  • 3,553
  • 9
  • 43
  • 60
  • 2
    Running in debug mode could provide some more useful info `gunicorn onbytes.wsgi:application --debug --log-level debug`. – famousgarkin Jul 08 '14 at 19:19

5 Answers5

36

Probably there is an issue in your application, not in gunicorn.

Try:

gunicorn --log-file=- onbytes.wsgi:application

Since the version R19, Gunicorn doesn’t log by default in the console and the --debug option was deprecated.

Mauro
  • 508
  • 3
  • 5
24

Adding --preload the gunincorn command showed me that I had to do :

pip install ordereddict

That package was missing.

Ghasem
  • 14,455
  • 21
  • 138
  • 171
Hanynowsky
  • 2,970
  • 5
  • 32
  • 43
  • 2
    Thanks. In my case, adding the `--preload` was the secret ingredient to get useful debug output that pointed at the underlying error in my app. `--log-file` and `--log-level debug` did not help much. – zlovelady Apr 16 '17 at 22:41
  • 1
    This. this. this. All of the other "show me better logs" options only displayed the same error in different places. This one also showed me the actual problem - in my case it was missing an __init__.py – TheGrimmScientist Jul 15 '17 at 00:37
  • I would make a version of this the correct answer if I could -- `gunicorn --preload` actually gave me a traceback to figure out what was failing – Alvin Aug 05 '19 at 04:29
13

I had a similar problem and it was because i was running the command in the wrong directory. In a standard django installation, try running gunicorn in the same directory that 'manage.py'

Micho
  • 928
  • 9
  • 11
1

in my case after adding --preload to Procfile, I understand that I should install psycopg2-binary with pip:

pip install psycopg2-binary
Ali dashti
  • 360
  • 2
  • 17
  • 1
    amazing! this fixes when `mlflow server` doesnt work; one might also have to `pip install boto3 protobuf==3.20.* ` might be worth trying without boto3 though – gndps Jun 24 '22 at 23:20
0

My case I was running a docker file that wasn't updated with all the necessary requirements.txt dependencies, so when booting the containers it failed "ModuleNotFound" and eventually threw the "worker failed to boot" error as well.

Adding the Module that was not found to the requirements.txt file and rebuilding the docker containers solved this error for me.

Nick Green
  • 101
  • 1
  • 9