2017-10-09 196 views
0

你好,我有一个django应用程序。我的整个系统配置如下:python 3,django 1.11,eventlet 0.21.0。Eventlet is_monkey_patched问题错误

1)Nginx的作为上游服务器:

upstream proj_server { 
     server unix:///tmp/proj1.sock fail_timeout=0; 
     server unix:///tmp/proj2.sock fail_timeout=0; 
} 

2)监控制工人。有一个gunicorn工人:

[program:proj] 
command=/home/vagrant/.virtualenvs/proj/bin/gunicorn -c /vagrant/proj/proj/proj/deploy/gunicorn.small.conf.py proj.wsgi:application 
directory=/vagrant/proj/proj/proj/deploy 
user=www-data 
autostart=true 
autorestart=true 
stdout_logfile=/var/log/supervisor/proj.log 

3)这是一个gunicorn.small.conf内容:

bind = ["unix:///tmp/proj1.sock", "unix:///tmp/proj2.sock"] 
pythonpath = "/vagrant/proj/proj/proj/deploy" 
workers = 2 
worker_class = "eventlet" 
worker_connections = 10 
timeout = 60 
graceful_timeout = 60 

4),这是proj.wsgi内容:

""" 
WSGI config for proj project. 

This module contains the WSGI application used by Django's development server 
and any production WSGI deployments. It should expose a module-level variable 
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover 
this application via the ``WSGI_APPLICATION`` setting. 

Usually you will have the standard Django WSGI application here, but it also 
might make sense to replace the whole Django WSGI application with a custom one 
that later delegates to the Django one. For example, you could introduce WSGI 
middleware here, or combine a Django application with an application of another 
framework. 

""" 
import eventlet 
eventlet.monkey_patch() 
from eventlet import wsgi 
import django.core.handlers.wsgi 
import os 

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

# This application object is used by any WSGI server configured to use this 
# file. This includes Django's development server, if the WSGI_APPLICATION 
# setting points here. 
from django.core.wsgi import get_wsgi_application 
application = get_wsgi_application() 

# Apply WSGI middleware here. 
# from helloworld.wsgi import HelloWorldApplication 
# application = HelloWorldApplication(application) 

所以,你可以看到有一个链:nginx作为一个上游服务器调用其中一个使用两个socket的gunicorn eventlet工人proj1.sockproj2.sock。 请注意,根据eventlet文档,我尽可能早地尝试使用eventlet.monkey_patch()。最适合的地方是proj.wsgi首先由gunicorn调用。

但是看起来库并不是猴子修补的。

要检查这个我加入凸出/凸出/凸出/ __ init__.py下面的代码(由Django应用程序称为第一模块):

import eventlet 
import os 
print("monkey patched os is: " + str(eventlet.patcher.is_monkey_patched('os'))) 
print("monkey patched select is: " + str(eventlet.patcher.is_monkey_patched('select'))) 
print("monkey patched socket is: " + str(eventlet.patcher.is_monkey_patched('socket'))) 
print("monkey patched time is: " + str(eventlet.patcher.is_monkey_patched('time'))) 
print("monkey patched subprocess is: " + str(eventlet.patcher.is_monkey_patched('subprocess'))) 

then i issued **./manage.py check** and got that answer: 

monkey patched os is: false 
monkey patched select is: false 
monkey patched socket is: false 
monkey patched time is: false 
monkey patched subprocess is: false 

我在做什么错?

回答

1

如果将proj.wsgi文件内容更改为一行raise Exception,该怎么办?这应该消除嫌疑人的eventlet。

我不擅长与Django的,这里是一个纯粹的猜测:

    基于名称
  • ,当WSGI服务器即将启动
  • manage.py check似乎并没有被相关执行proj.wsgi远程网络服务(WSGI),似乎是一种通用的管理命令,所以它不应该执行WSGI相关的代码

一个可能的解决方案,从你的问题的文本采取:

凸出/凸出/凸出/ 初始化的.py(第一,通过Django的应用

尝试打电话把monkey_patch呼叫在那里模块。

P.S .:你不需要主管gunicorn,它的主进程(仲裁)被设计为永远运行,尽管工人有问题。

+0

我使用主管,因为有很多服务器上的进程应该管理,不仅gunicorn。什么abou wsgi - 有道理。我会尝试你的建议,谢谢。 –