【发布时间】:2022-12-16 05:17:24
【问题描述】:
背景
我有一个严重依赖 iobound 的 Django 应用程序,所以根据我读过的文档,我试图让 gunincorn 与 gevent 一起工作以获得最佳性能。
错误
dev1 | Patching Started
dev1 | /app/Dev/wsgi.py:19: MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on Python 3.7. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016. Modules that had direct imports (NOT patched): ['urllib3.util (/usr/local/lib/python3.9/site-packages/urllib3/util/__init__.py)', 'urllib3.util.ssl_ (/usr/local/lib/python3.9/site-packages/urllib3/util/ssl_.py)'].
dev1 | monkey.patch_all(thread=False, select=False)
dev1 | Patching Done
dev1 | /usr/local/lib/python3.9/site-packages/paramiko/transport.py:236: CryptographyDeprecationWarning: Blowfish has been deprecated
dev1 | "class": algorithms.Blowfish,
dev1 | /usr/local/lib/python3.9/site-packages/gunicorn/workers/ggevent.py:38: MonkeyPatchWarning: Patching more than once will result in the union of all True parameters being patched
dev1 | monkey.patch_all()
dev1 | /usr/local/lib/python3.9/site-packages/gunicorn/workers/ggevent.py:38: MonkeyPatchWarning: Patching more than once will result in the union of all True parameters being patched
dev1 | monkey.patch_all()
dev1 | /usr/local/lib/python3.9/site-packages/gunicorn/workers/ggevent.py:38: MonkeyPatchWarning: Patching more than once will result in the union of all True parameters being patched
dev1 | monkey.patch_all()
...
设置
wsgi.py
# Needs to happen first
print("Patching Started")
from gevent import monkey
monkey.patch_all(thread=False, select=False)
# monkey.patch_all()
from psycogreen.gevent import patch_psycopg
patch_psycopg()
print("Patching Done")
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Dev.settings')
application = get_wsgi_application()
Docker-Compose 命令
command:
- |
gunicorn Dev.wsgi:application
--bind 0.0.0.0:8000
--workers 10
--timeout 30
--preload
--access-logfile /dev/stdout
--worker-class gevent"
问题
所以在我看来,我应该在 gunicorn 一开始拾起它时将我的 monkey.patch() 放在正确的位置,但不知何故 urllib3.util 首先加载。我把猴子补丁放在正确的地方了吗?
【问题讨论】:
标签: python django gunicorn gevent