首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Eventlet is_monkey_patched发出False

Eventlet is_monkey_patched发出False
EN

Stack Overflow用户
提问于 2017-10-09 11:08:17
回答 1查看 385关注 0票数 0

你好,我有一个django应用程序。我的整个系统配置如下: python 3、django 1.11、eventlet0.21.0。

1) Nginx作为上游服务器:

代码语言:javascript
运行
复制
upstream proj_server {
        server unix:///tmp/proj1.sock fail_timeout=0;
        server unix:///tmp/proj2.sock fail_timeout=0;
}

( 2)控制工人的主管。有个枪手:

代码语言:javascript
运行
复制
[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内容:

代码语言:javascript
运行
复制
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内容:

代码语言:javascript
运行
复制
"""
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作为上游服务器,使用两个套接字( proj1.sockproj2.sock )调用一个gunicorn事件工作者。注意,根据事件文档,我尝试尽早使用eventlet.monkey_patch()。最合适的地方是proj.wsgi,它最初是由火鸟命名的。

然而,图书馆似乎不是猴子的补丁。

为了检查这一点,我将以下代码添加到proj/proj/proj/__init__.py ( django应用程序调用的第一个模块)中:

代码语言:javascript
运行
复制
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

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-09 23:34:28

如果将proj.wsgi文件内容更改为一行raise Exception会怎么样?这应该可以消除嫌疑人的突发事件。

我对Django不太在行,这里有一个纯粹的推测:

  • 基于名称,在WSGI服务器即将启动时执行proj.wsgi。
  • manage.py check似乎与远程网络服务( WSGI )无关,似乎是一个通用的管理命令,因此不应该执行WSGI相关的代码。

一种可能的解决办法,摘自你的问题案文:

proj/proj/proj/init.py ( django应用程序调用的第一个模块)

试着把monkey_patch电话放进去。

P.S.:你不需要监督,它的主程序(仲裁者)被设计成永远运行,尽管与工人之间存在问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46645014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档