首页 > 其他分享 >关于gunicorn与异步兼容性问题:AttributeError: module 'select' has no attribute 'epoll'

关于gunicorn与异步兼容性问题:AttributeError: module 'select' has no attribute 'epoll'

时间:2024-01-15 14:57:31浏览次数:32  
标签:python3.10 gunicorn lib no py File 兼容性问题 home line

关于gunicorn与异步兼容性问题:AttributeError: module 'select' has no attribute 'epoll'

背景:

  • 介绍:
  在使用gunicorn、Flask & flask-sockets 部署,实现websocket协议中同类消息阻塞,不同类消息不阻塞场景。
  • 异常:
    [2024-01-15 10:22:16 +0800] [31655] [ERROR] Exception in worker process
    Traceback (most recent call last):
      File "/home/venv/lib/python3.10/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
        worker.init_process()
      File "/home/venv/lib/python3.10/site-packages/gunicorn/workers/ggevent.py", line 162, in init_process
        super().init_process()
      File "/home/venv/lib/python3.10/site-packages/gunicorn/workers/base.py", line 133, in init_process
        self.load_wsgi()
      File "/home/venv/lib/python3.10/site-packages/gunicorn/workers/base.py", line 142, in load_wsgi
        self.wsgi = self.app.wsgi()
      File "/home/venv/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi
        self.callable = self.load()
      File "/home/venv/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
        return self.load_wsgiapp()
      File "/home/venv/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
        return util.import_app(self.app_uri)
      File "/home/venv/lib/python3.10/site-packages/gunicorn/util.py", line 331, in import_app
        mod = importlib.import_module(module)
      File "/home/nlu_common/miniconda3/lib/python3.10/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
     。。。。。。包含很多具体代码,没有意义。。。。。。
      File "/home/venv/lib/python3.10/site-packages/dns/resolver.py", line 38, in <module>
        import dns.query
      File "/home/venv/lib/python3.10/site-packages/dns/query.py", line 52, in <module>
        import httpx
      File "/home/venv/lib/python3.10/site-packages/httpx/__init__.py", line 2, in <module>
        from ._api import delete, get, head, options, patch, post, put, request, stream
      File "/home/venv/lib/python3.10/site-packages/httpx/_api.py", line 4, in <module>
        from ._client import Client
      File "/home/venv/lib/python3.10/site-packages/httpx/_client.py", line 30, in <module>
        from ._transports.default import AsyncHTTPTransport, HTTPTransport
      File "/home/venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 30, in <module>
        import httpcore
      File "/home/venv/lib/python3.10/site-packages/httpcore/__init__.py", line 1, in <module>
        from ._api import request, stream
      File "/home/venv/lib/python3.10/site-packages/httpcore/_api.py", line 5, in <module>
        from ._sync.connection_pool import ConnectionPool
      File "/home/venv/lib/python3.10/site-packages/httpcore/_sync/__init__.py", line 1, in <module>
        from .connection import HTTPConnection
      File "/home/venv/lib/python3.10/site-packages/httpcore/_sync/connection.py", line 12, in <module>
        from .._synchronization import Lock
      File "/home/venv/lib/python3.10/site-packages/httpcore/_synchronization.py", line 13, in <module>
        import trio
      File "/home/venv/lib/python3.10/site-packages/trio/__init__.py", line 22, in <module>
        from ._core import TASK_STATUS_IGNORED as TASK_STATUS_IGNORED  # isort: split
      File "/home/venv/lib/python3.10/site-packages/trio/_core/__init__.py", line 21, in <module>
        from ._local import RunVar, RunVarToken
      File "/home/venv/lib/python3.10/site-packages/trio/_core/_local.py", line 9, in <module>
        from . import _run
      File "/home/venv/lib/python3.10/site-packages/trio/_core/_run.py", line 2787, in <module>
        from ._io_epoll import (
      File "/home/venv/lib/python3.10/site-packages/trio/_core/_io_epoll.py", line 202, in <module>
        class EpollIOManager:
      File "/home/venv/lib/python3.10/site-packages/trio/_core/_io_epoll.py", line 203, in EpollIOManager
        _epoll: select.epoll = attr.ib(factory=select.epoll)
    AttributeError: module 'select' has no attribute 'epoll'. Did you mean: 'poll'?
    [2024-01-15 10:22:16 +0800] [31655] [INFO] Worker exiting (pid: 31655)
    [2024-01-15 10:22:17 +0800] [31652] [INFO] Shutting down: Master
    [2024-01-15 10:22:17 +0800] [31652] [INFO] Reason: Worker failed to boot.
    • 表现:AttributeError: module 'select' has no attribute 'epoll'. Did you mean: 'poll'?

项目介绍

  • 框架使用Flask + flask-sockets 搭建
  • 内部业务使用异步转同步,例如:asnyc、httpx等
  • 交互协议http、grpc、websocket
  • 部署:gunicorn、gevent

问题分析

  1. 部署方式分析:
    • 非Gunicorn部署(window & linux)
      from http_server.handle import app
      
      from gevent import pywsgi
      from geventwebsocket.handler import WebSocketHandler
      
      server = pywsgi.WSGIServer(('0.0.0.0', 50003), app, handler_class=WebSocketHandler)
      server.serve_forever()
      可正常提供服务
      epoll支持:Python官方文档
      select.epoll([suzegubt=-1])
          (only supported on Linux 2.5.44 and newer.) Returns an edge polling object,
          which can be used as Edge or Level Triggered interface for I/O events;
          see section Edge and Level Trigger Polling (epoll) Objects below for the methods supported by epolling objects.
    • Gunicorn部署:如背景介绍
    • 结论:上述问题与gunicorn兼容性问题:gunicorn(gevent) <=> trio(epoll) ......> httpcore ......> httpx ......>dnspython
  2. 资源搜索分析:
    • Gunicorn(Gevent) 与 trio 存在兼容性问题:https://github.com/gevent/gevent/issues/2008
      • 无直接解决方案
    • 通过配置
      from gevent import monkey
      monkey.patch_all(select=False)
          or
    export EVENTLET_NO_GREENDNS=yes
      • 对结果无效
  3. 版本兼容性处理-降级
    • 当前版本
      • gevent                    23.9.1
        gevent-websocket          0.10.1
        gunicorn                  21.2.0
        dnspython                 2.4.2
        httpcore                  0.17.3
        httpx                     0.24.1
        trio                      0.24.0
        trio-websocket            0.11.1
    • 经过相关包降级:
      • dsnpython => 2.3.0 无用
      • trio => 0.22.2 升降级无用
      • httpcore => 0.17.1 解决

结论:

    AttributeError: module 'select' has no attribute 'epoll' 异常原因:
  1. gunicorn部署表现:trio 与 gunicorn(gevent)的不兼容
  2. 解决办法:使用httpcore低版本 <= 0.17.12

标签:python3.10,gunicorn,lib,no,py,File,兼容性问题,home,line
From: https://www.cnblogs.com/spaceapp/p/17965345

相关文章

  • Arduino部分C语言含义之--“::”
    "::“在C++中表示作用域,和所属关系。”::"是运算符中等级最高的。有三种作用。1.作用域符号例如:A,B表示两个类,在A,B中都有成员member。那么:A::member就表示类A中的成员member。B::member就表示类B中的成员member。2.全局作用域符号charzhou;//全局变量voids......
  • 推荐一个node版本管理工具nvm
    nvm是一款Node.js版本管理工具,允许用户通过命令行快速安装、切换和管理不同的Node.js版本。nvm只适用于macOS和Linux用户的项目,如果是Windows用户,可以使用 nvm-windows 、nodist 或 nvs 替换。安装方式macOS下载方式:#方式1浏览器打开下面链接下载https:/......
  • nvm管理nodejs
    gitub搜索nvm-windows,选择收藏最多的点击release,选择最新的版本下载,安装:修改nvm和npm的路径打开nvm文件夹,找到settings.txt文件,修改settings.txt的内容(主要为了解决nvm安装node时,使得node与npm对应的安装成功)root:C:\nvmpath:C:\ProgramFiles\nodejs//将npm镜像改为淘......
  • ICLR 2022: Anomaly Transformer论文阅读笔记(2) 深度解析代码
    AnomalyTransformer是一个由Transformer:AttentionIsAllYouNeed启发出的检测时间序列异常点的无监督学习算法。在这一篇我会深度解析论文算法以及代码的一一对应,让人更方便能读懂和使用源代码。阅读笔记前篇:ICLR2022:AnomalyTransformer论文阅读笔记+代码复现阅读前提......
  • 在Linux中安装和配置Node.js与Express.js创建HTTP服务器
    在Linux环境中,安装和配置Node.js与Express.js来创建一个HTTP服务器需要一系列的步骤。下面是一个详细的指南,帮助你在Linux上设置这个环境。步骤1:安装Node.js首先,你需要确保你的Linux系统已经安装了Node.js。你可以通过以下命令来检查是否已经安装:bash复制代码node-v如果已经安装,它......
  • 统信UOS/麒麟KYLINOS修改图标显示名称
    原文链接:统信UOS/麒麟KYLINOS修改图标显示名称hello,大家好啊!今天我要给大家介绍的是在统信UOS及麒麟KYLINOS操作系统上如何修改软件的名称。这种自定义可以帮助您更快地识别和访问常用的应用程序,也可以使您的桌面环境更加个性化。我们将通过修改/usr/share/applications目录下的.de......
  • Arduino或其他微控制器来控制TB67S109A
    TB67S109A是一款步进电机驱动器,它没有特定的代码。但是,您可以使用Arduino或其他微控制器来控制TB67S109A。以下是一个简单的示例代码,用于控制TB67S109A的步进电机:#include<Stepper.h>//定义步进电机的引脚constintstepPin=8;constintdirPin=9;//创建步进电机对象......
  • MYISAM和INNODB的区别
    INNODB支持事务,而MYISAM不支持事务。INNODB支持外键,而MYISAM不支持外键。MYISAM中B+Tree的数据结构存储的内容是实际数据的地址值,它的索引和实际数据是分开的,只不过使用索引指向了实际数据。这种索引的模式被称为非聚集索引。InnoDB中B+树的数据结构中存储的都是实......
  • 在nodejs环境使用promise函数
     如果单纯的使用promise,对环境比较简单,只需要一个js文件即可。//constp1=newPromise((resolve,reject)=>{//setTimeout(()=>{//resolve('resolve')//},1000)//})//constp2=newPromise((resolve,reject)=>{//setTimeout(()......
  • 解决No dashboards are active for the current data set
    出现这个页面 尝试了这个博主的所有方法还是不对【解决方案汇总】Nodashboardsareactiveforthecurrentdataset.Probablecauses-CSDN博客解决的最终方法:在terminal下,将目录切换到所运行代码的这一级目录中,再运行  tensorboard--logdir=logs就可以了......