2017-10-09 43 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 - 有道理。我會嘗試你的建議,謝謝。 –