代码之家  ›  专栏  ›  技术社区  ›  Roman Storozhenko

Eventlet is\u monkey\u修补问题错误

  •  0
  • Roman Storozhenko  · 技术社区  · 7 年前

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

    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) 这是一个 古尼科恩。小的形态 内容:

    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) 这是 项目。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使用两个套接字调用gunicorn eventlet worker之一 proj1.sock 项目2.sock . eventlet。monkey_补丁() 越早越好。最合适的地方是 项目。wsgi公司 这首先被古尼科恩称为。

    然而,图书馆似乎并没有被修补过。

    项目/项目/项目/初始化。py公司

    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 回复  |  直到 7 年前
        1
  •  2
  •   temoto    7 年前

    如果你改变项目怎么办。wsgi文件内容到一行 raise Exception ? 这应该可以消除嫌疑人的事件。

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

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

    项目/项目/项目/ 初始化

    试着把monkey_patch call放进去。

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