Python gunicorn.errors.HaltServer: <HaltServer 'Worker 启动失败。' 3> 姜戈
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24488891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3> django
提问by Shiva Krishna Bavandla
I have a django app and trying to set it up with gunicorn first and later with supervisor and nginx.
我有一个 django 应用程序,并尝试先用 gunicorn 设置它,然后再用主管和 nginx 设置它。
The app is running with the normal django command perfectly like python manage.py runserver
该应用程序正在使用正常的 django 命令运行,就像 python manage.py runserver
I installed the gunicorn using pip like pip install gunicorn
and django version is 1.5.3
我使用 pip like 安装了 gunicorn pip install gunicorn
,django 版本是1.5.3
when i run the below command inside the virtual env like below
当我在虚拟环境中运行以下命令时,如下所示
gunicorn hello.wsgi:application -b xx.xxx.xxx.xx:8000
and faced the error
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>
So why actually the above error is encountered and whats the fix ?
那么为什么实际上会遇到上述错误,修复方法是什么?
采纳答案by Shiva Krishna Bavandla
Actually the problem here was the wsgi file itself, previously before django 1.3 the wsgi file was named with an extension of .wsgi
, but now in the recent versions it will be created with and extension of .py
that is the wsgi file must be a python module
其实这里的问题是WSGI文件本身,以前的Django 1.3之前的WSGI文件的名字用的延伸.wsgi
,但现在最近的版本将与创建和扩展.py
那就是WSGI文件必须是一个Python模块
so the file should be hello_wsgi.py
and command should be
所以文件应该是hello_wsgi.py
,命令应该是
gunicorn hello:application -b xx.xxx.xxx.xx:8000
回答by Tomasz Jakub Rup
You don't showed a full output. It's probably looks like
你没有显示完整的输出。它可能看起来像
$ 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>
Last trackback is almost the same, but before You see required informations:
最后引用几乎相同,但在您看到所需信息之前:
ImportError: No module named elcarweb.wsgi
If You see this error, then solution is run gunicorn with --chdir=/your/app/dir
parameter.
如果您看到此错误,则解决方案是使用--chdir=/your/app/dir
参数运行 gunicorn 。
回答by Michal Ambroz
I got the very same error.
Gunicornwas working when executed as root, but failed this way when executed as non-privileged user.
In my case I install the 'dataset' python module with 'pip install dataset' and it screwed the permissions on /usr/lib/python2.7/site-packages/dataset
to be readable only by root account. On other module installed as dependency like that was normality.
我得到了同样的错误。
Gunicorn在以 root 身份执行时正常工作,但在以非特权用户身份执行时以这种方式失败。就我而言,我使用“pip install dataset”安装了“dataset”python 模块,并将权限/usr/lib/python2.7/site-packages/dataset
设置为只能由 root 帐户读取。在作为依赖项安装的其他模块上是正常的。
Fix :
使固定 :
chmod -R a+rX /usr/lib/python2.7/site-packages/dataset*
chmod -R a+rX /usr/lib/python2.7/site-packages/normality*
Some another issue was with the yaml package auto-installed by pip, but I have not found what exactly. The fix was to reinstall from fedora package:
另一个问题是 pip 自动安装的 yaml 包,但我还没有找到究竟是什么。修复方法是从 fedora 包中重新安装:
dnf -y install python-yaml
回答by mattdedek
I also had a similar error in Ubuntu 16.04, Django 1.11, using systemd.
我在使用 systemd 的 Ubuntu 16.04、Django 1.11 中也有类似的错误。
My problem was that I had split my settings out into separate files; ie: instead of having all settings in project/settings.py, I have a few settings files like project/settings/dev.py.
我的问题是我已将设置拆分为单独的文件;即:我没有在 project/settings.py 中包含所有设置,而是有一些设置文件,例如 project/settings/dev.py。
I had to update DJANGO_SETTINGS_MODULE in the project/wsgi.py file from:
我必须从以下位置更新 project/wsgi.py 文件中的 DJANGO_SETTINGS_MODULE:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
to
到
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings.dev")
then gunicorn worked.
然后 gunicorn 起作用了。
回答by john zhang
run guncorn with --preload can see the error log, like this
用--preload 运行 guncorn 可以看到错误日志,像这样
gunicorn app:application --preload -b 0.0.0.0:5000
This will usually give you a more detailed error message.
这通常会为您提供更详细的错误消息。
回答by Vsevolod Gromov
For anyone facing the same issue, the problem is usually something in django itself. Activate your venv and run ./manage.py runserver
对于任何面临同样问题的人来说,问题通常出在 django 本身。激活你的 venv 并运行 ./manage.py runserver
This will usually give you a more detailed error message.
这通常会为您提供更详细的错误消息。