gunicorn.errors.HaltServer:<haltserver'worker =“”failed =“”to =“”boot。'=“”3 =“”> django </haltserver>

时间:2014-06-30 11:15:21

标签: python django gunicorn

我有一个django应用程序,并尝试先用gunicorn设置它,然后再用supervisor和nginx设置它。

该应用程序正常运行时使用正常的django命令,就像python manage.py runserver

一样

我使用像pip install gunicorn这样的pip安装了gunicorn,而django版本是1.5.3

当我在虚拟环境中运行以下命令时,如下所示

gunicorn hello.wsgi:application -b xx.xxx.xxx.xx:8000并面临错误

Traceback (most recent call last):
  File "/root/Envs/proj/bin/gunicorn", line 9, in <module>
    load_entry_point('gunicorn==19.0.0', 'console_scripts', 'gunicorn')()
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 166, in run
    super(Application, self).run()
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
    Arbiter(self).run()
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 169, in run
    self.manage_workers()
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
    self.spawn_workers()
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 537, in spawn_workers
    time.sleep(0.1 * random.random())
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
    self.reap_workers()
  File "/root/Envs/proj/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>

那么为什么实际遇到上述错误并修复了什么?

6 个答案:

答案 0 :(得分:26)

实际上这里的问题是wsgi文件本身,之前在django 1.3之前,wsgi文件的扩展名为.wsgi,但现在在最近的版本中,它将使用{{1}的扩展名创建那就是wsgi文件必须是python模块

所以文件应该是.py,命令应该是

hello_wsgi.py

答案 1 :(得分:8)

您没有显示完整输出。它可能看起来像

$(function() {
$('.monthYearPicker').datepicker({
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    dateFormat: 'MM yy'
}).focus(function() {
    var thisCalendar = $(this);
    $('.ui-datepicker-calendar').detach();
    $('.ui-datepicker-close').click(function() {
        var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
        var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
        thisCalendar.datepicker('setDate', new Date(year, month, 1));
        });
    });
});

最后的引用几乎相同,但在您看到所需的信息之前:

$ gunicorn elcarweb.wsgi
[2015-10-27 21:01:47 +0000] [5429] [INFO] Starting gunicorn 19.2.1
[2015-10-27 21:01:47 +0000] [5429] [INFO] Listening at: http://127.0.0.1:8000 (5429)
[2015-10-27 21:01:47 +0000] [5429] [INFO] Using worker: sync
[2015-10-27 21:01:47 +0000] [5434] [INFO] Booting worker with pid: 5434
[2015-10-27 21:01:47 +0000] [5434] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 503, in spawn_worker
    worker.init_process()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 116, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
    __import__(module)
ImportError: No module named elcarweb.wsgi
Traceback (most recent call last):
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 503, in spawn_worker
    worker.init_process()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 116, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
    __import__(module)
ImportError: No module named elcarweb.wsgi
[2015-10-27 21:01:47 +0000] [5434] [INFO] Worker exiting (pid: 5434)
Traceback (most recent call last):
  File "/home/tomek/Elcar/elcarweb/env/bin/gunicorn", line 11, in <module>
    sys.exit(run())
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 189, in run
    super(Application, self).run()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 170, in run
    self.manage_workers()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 473, in manage_workers
    self.spawn_workers()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 537, in spawn_workers
    time.sleep(0.1 * random.random())
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 210, in handle_chld
    self.reap_workers()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 455, in reap_workers
    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

如果您看到此错误,则解决方案是使用ImportError: No module named elcarweb.wsgi 参数运行gunicorn。

答案 2 :(得分:4)

我在使用systemd的Ubuntu 16.04,Django 1.11中也有类似的错误。

我的问题是我将设置拆分为单独的文件;即:我没有在project / settings.py中设置所有设置,而是有一些设置文件,如project / settings / dev.py。

我必须更新项目/ wsgi.py文件中的DJANGO_SETTINGS_MODULE:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")  

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings.dev")
然后枪手工作了。

答案 3 :(得分:2)

使用--preload运行guncorn可以看到错误日志,例如

gunicorn app:application --preload -b 0.0.0.0:5000 

这通常会为您提供更详细的错误消息。

答案 4 :(得分:1)

我得到了同样的错误。 Gunicorn在以root身份执行时正在工作,但在以非特权用户身份执行时以这种方式失败。 在我的情况下,我使用'pip install dataset'安装'dataset'python模块,它将/usr/lib/python2.7/site-packages/dataset上的权限搞砸,只能由root帐户读取。在其他模块上安装为依赖,就像是正常一样。

修复:

chmod -R a+rX /usr/lib/python2.7/site-packages/dataset*
chmod -R a+rX /usr/lib/python2.7/site-packages/normality*

另一个问题是由pip自动安装的yaml包,但我还没有找到确切的内容。修复是从fedora包重新安装:

dnf -y install python-yaml

答案 5 :(得分:0)

对于面临相同问题的任何人,问题通常出在Django本身中。 激活您的venv并运行./manage.py runserver

这通常会为您提供更详细的错误消息。