芹菜工人抛出属性错误:模块'os'没有属性'register_at_fork'



我在windows机器上运行celener worker(版本4.4(,当我使用-P eventlet选项运行worker时,它会引发Attribute错误。错误日志如下:-

pipenv run celery worker -A src.celery_app -l info -P eventlet --without-mingle --without-heartbeat --without-gossip -Q queue1 -n worker1
Traceback (most recent call last):
File "d:python37librunpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:python37librunpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:UsersG-US01.Test.virtualenvscelery-z5n-38VtScriptscelery.exe__main__.py", line 7, in <module>
File "c:usersg-us01.test.virtualenvscelery-z5n-38vtlibsite-packagescelery__main__.py", line 14, in main
maybe_patch_concurrency()
File "c:usersg-us01.test.virtualenvscelery-z5n-38vtlibsite-packagescelery__init__.py", line 152, in maybe_patch_concurrency
patcher()
File "c:usersg-us01.test.virtualenvscelery-z5n-38vtlibsite-packagescelery__init__.py", line 109, in _patch_eventlet
eventlet.monkey_patch()
File "c:usersg-us01.test.virtualenvscelery-z5n-38vtlibsite-packageseventletpatcher.py", line 334, in monkey_patch
fix_threading_active()
File "c:usersg-us01.test.virtualenvscelery-z5n-38vtlibsite-packageseventletpatcher.py", line 331, in fix_threading_active
_os.register_at_fork(
AttributeError: module 'os' has no attribute 'register_at_fork'

我已经在虚拟环境中安装了eventlet,pipfile的内容如下:-

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
rope = "*"
autopep8 = "*"
[packages]
eventlet = "*"
psutil = "*"
celery = "*"
pythonnet = "*"
redis = "*"
gevent = "*"
[requires]
python_version = "3.7"

请告诉我哪里出了问题。

os.register_at_fork是自Python 3.7以来可用的新函数,它仅适用于Unix系统(源代码来自Python文档(,Eventlet使用它来修补threading库。

Eventlet Github中打开了一个问题:https://github.com/eventlet/eventlet/issues/644

所以我认为Celery -A app worker -l info -P eventlet不再是Windows的好替代品。

就我个人而言:

Celery -A app worker -l info

并对Windows 10Python 3.7Celery 4.4.7进行了实验验证。

您面临这种情况的一个原因是因为Celery在预分叉模型上工作。因此,如果底层操作系统不支持它,你将很难运行芹菜。据我所知,这个模型不适用于Windows内核。

如果你想让Cygwin在windows上运行,或者让Linux子系统可用于windows ,你仍然可以使用它

来源:-

  1. 如何在窗户上种芹菜
  2. https://docs.celeryproject.org/en/stable/faq.html#does-芹菜支撑窗

如@金奕峰,os.register_at_fork是在github上的eventlet v0.27.0 c.f.提交比较中引入的。在虚拟环境的包列表中指定0.26.0版本可能会解决问题(目前(。

是eventlet版本0.26;pip安装事件==0.26

最新更新