gunicorn worker (gevent) 使用 python 3.11 启动失败

问题描述 投票:0回答:2

我们使用 alpine 3.16.2、python 3.11.0 和 pip 22.3 以及通过 pip 安装的一堆其他库(django、google 等)

gunicorn==20.1.0
gevent==22.10.2
greenlet==2.0.1

gunicorn worker (gevent) failed to boot, please find error details as below:

    
    [2022-11-30 09:19:27 +0000] [6] [INFO] Starting gunicorn 20.1.0
    [2022-11-30 09:19:27 +0000] [6] [INFO] Listening at: https://0.0.0.0:8443 (6)
    [2022-11-30 09:19:27 +0000] [6] [INFO] Using worker: gevent
    [2022-11-30 09:19:27 +0000] [7] [INFO] Booting worker with pid: 7
    [2022-11-30 09:19:28 +0000] [8] [INFO] Booting worker with pid: 8
    [2022-11-30 09:19:29 +0000] [7] [ERROR] Exception in worker process
    Traceback (most recent call last):
      File "/usr/local/lib/python3.11/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
        worker.init_process()
      File "/usr/local/lib/python3.11/site-packages/gunicorn/workers/ggevent.py", line 144, in init_process
        self.patch()
      File "/usr/local/lib/python3.11/site-packages/gunicorn/workers/ggevent.py", line 38, in patch
        monkey.patch_all()
      File "/usr/local/lib/python3.11/site-packages/gevent/monkey.py", line 1263, in patch_all
        patch_thread(Event=Event, _warnings=_warnings)
      File "/usr/local/lib/python3.11/site-packages/gevent/monkey.py", line 200, in ignores
        return func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/site-packages/gevent/monkey.py", line 791, in patch_thread
        _patch_existing_locks(threading_mod)
      File "/usr/local/lib/python3.11/site-packages/gevent/monkey.py", line 672, in _patch_existing_locks
        if isinstance(o, rlock_type):
           ^^^^^^^^^^^^^^^^^^^^^^^^^
    **ReferenceError: weakly-referenced object no longer exists**
    [2022-11-30 09:19:29 +0000] [7] [INFO] Worker exiting (pid: 7)
    [2022-11-30 09:19:29 +0000] [8] [ERROR] Exception in worker process
    Traceback (most recent call last):
      File "/usr/local/lib/python3.11/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
        worker.init_process()
      File "/usr/local/lib/python3.11/site-packages/gunicorn/workers/ggevent.py", line 144, in init_process
        self.patch()
      File "/usr/local/lib/python3.11/site-packages/gunicorn/workers/ggevent.py", line 38, in patch
        monkey.patch_all()
      File "/usr/local/lib/python3.11/site-packages/gevent/monkey.py", line 1263, in patch_all
        patch_thread(Event=Event, _warnings=_warnings)
      File "/usr/local/lib/python3.11/site-packages/gevent/monkey.py", line 200, in ignores
        return func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/site-packages/gevent/monkey.py", line 791, in patch_thread
        _patch_existing_locks(threading_mod)
      File "/usr/local/lib/python3.11/site-packages/gevent/monkey.py", line 672, in _patch_existing_locks
        if isinstance(o, rlock_type):
           ^^^^^^^^^^^^^^^^^^^^^^^^^
    **ReferenceError: weakly-referenced object no longer exists**
    [2022-11-30 09:19:29 +0000] [8] [INFO] Worker exiting (pid: 8)
    [2022-11-30 09:19:30 +0000] [6] [WARNING] Worker with pid 7 was terminated due to signal 15
    [2022-11-30 09:19:30 +0000] [6] [INFO] Shutting down: Master
    [2022-11-30 09:19:30 +0000] [6] [INFO] Reason: Worker failed to boot.
    

使用 alpine 3.16.2、python 3.10.7 和 pip 22.2.2 以及通过 pip 安装的同一批其他库(django、google 等)同样可以正常工作

有人可以帮忙吗,如果需要任何其他信息,请告诉我?

注意:- 关于如何进一步分类/调试的任何见解也很有帮助

python gunicorn gevent
2个回答
1
投票

尝试使用 3.10。我认为这是 Python 3.11 的问题。我花了半天时间尝试将一个新项目部署到 Heroku。无法弄清楚所以我从新开始并将python版本更改为3.10.9。这有效,适用于 3.10.9。部署时我在 PROJECT_NAME.wsgi 上收到模块未发现错误

根据这个网站,python 3.11 不支持 gunicorn 但它也说 3.10 不支持 gunicorn。 https://pyreadiness.org/3.11/


0
投票

事实证明 newrelic-admin 和 gevent 在这个版本的 python (3.11) 中不能相处(我们使用像 run newrelic-admin gunicorn 和一些配置参数 wsgi

我们对 gevent/monkey.py 进行猴子修补以捕获抛出的 ReferenceError 并尝试从中获取尽可能多的信息,然后我们看到了 newrelic 猴子补丁警告

所以,我们从运行命令中删除了 newrelic-admin 并在 WSGI 可调用变量 application(在 wsgi.py 中)之前初始化 newrelic 代理,它为我们解决了这个问题

© www.soinside.com 2019 - 2024. All rights reserved.