我一直在运行一个使用Celery运行任务的码头化烧瓶应用程序。为了运行该应用程序,我使用了带有eventlet的gunicorn,它使用alpine-linux发行版运行得很好。
然而,由于sklearn和其他库的一些问题,我不得不搬到ubuntu,现在我在运行我的应用程序时遇到了问题。
首先,我得到这个错误:
Error: class uri 'eventlet' invalid or not found:
[Traceback (most recent call last):
File "/myapp/env/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 11, in <module>
import eventlet
ModuleNotFoundError: No module named 'eventlet'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/myapp/env/lib/python3.6/site-packages/gunicorn/util.py", line 135, in load_class
mod = import_module('.'.join(components))
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/myapp/env/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 13, in <module>
raise RuntimeError("You need eventlet installed to use this worker.")
RuntimeError: You need eventlet installed to use this worker.
然后我尝试将pip install eventlet
添加到我的应用程序的Dockerfile中,现在我遇到了另一个错误:
Error: class uri 'eventlet' invalid or not found:
[Traceback (most recent call last):
File "/myapp/env/lib/python3.6/site-packages/gunicorn/util.py", line 135, in load_class
mod = import_module('.'.join(components))
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/myapp/env/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 11, in <module>
import eventlet
File "/myapp/env/lib/python3.6/site-packages/eventlet/__init__.py", line 10, in <module>
from eventlet import convenience
File "/myapp/env/lib/python3.6/site-packages/eventlet/convenience.py", line 7, in <module>
from eventlet.green import socket
File "/myapp/env/lib/python3.6/site-packages/eventlet/green/socket.py", line 21, in <module>
from eventlet.support import greendns
File "/myapp/env/lib/python3.6/site-packages/eventlet/support/greendns.py", line 69, in <module>
setattr(dns.rdtypes.IN, pkg, import_patched('dns.rdtypes.IN.' + pkg))
File "/myapp/env/lib/python3.6/site-packages/eventlet/support/greendns.py", line 59, in import_patched
return patcher.import_patched(module_name, **modules)
File "/myapp/env/lib/python3.6/site-packages/eventlet/patcher.py", line 126, in import_patched
*additional_modules + tuple(kw_additional_modules.items()))
File "/myapp/env/lib/python3.6/site-packages/eventlet/patcher.py", line 100, in inject
module = __import__(module_name, {}, {}, module_name.split('.')[:-1])
File "/myapp/env/lib/python3.6/site-packages/dns/rdtypes/IN/WKS.py", line 25, in <module>
_proto_tcp = socket.getprotobyname('tcp')
OSError: protocol not found
这就是我启动应用程序(start.sh
(的方式:
gunicorn -w 1 --worker-class eventlet --certfile=myapp/myapp.crt --keyfile=myapp/myapp.key --bind 0.0.0.0:5000 --log-config myapp/gunicorn.conf myapp.run:app
在我搬到一个基于ubuntu的容器之前,它一直工作得很好。
我在这里错过了什么?
我感谢你的帮助。
谢谢!
我也遇到了同样的问题,我发现这是由eventlet
的一些更新引起的。他们删除了eventlet.wsgi.ALREADY_HANDLED
,但gunicorn
仍在使用它。所以,你最好降级eventlet版本。
pip install gunicorn==20.1.0 eventlet==0.30.2
这是一个参考https://github.com/eventlet/eventlet/issues/702
我试了很多次,终于工作了,请检查这些:
- gunicorn==20.1.0 eventlet==0.30.2(错误源:https://github.com/benoitc/gunicorn/pull/2581)
- 3.10以下的python版本(错误源:https://github.com/eventlet/eventlet/issues/687)
如果您使用的是heroku,请编辑requisitions.txt,添加gunicorn和eventlet版本,并编辑runtime.txt;蟒蛇-3.9.13";(如果您使用的是heroku堆栈22(。如果你正在运行另一个heroku堆栈,请检查它的python兼容版本。(来源=https://devcenter.heroku.com/articles/python-support#supported-运行时(
我会发布我找到的解决方案,以防对任何人有用。
只是我错过了/etc/protocols
,这就是我修复它的方法:
我不得不在Dockerfile:中添加这一步骤
RUN apt-get -o Dpkg::Options::='--force-confmiss' install --reinstall -y netbase