gpt4 book ai didi

python celery 不工作

转载 作者:行者123 更新时间:2023-12-05 06:37:06 25 4
gpt4 key购买 nike

一般来说,我是 celery 和 python 的新手,想使用 celery 在应用程序中执行异步任务。当我试图查看它是如何工作时,演示应用程序本身无法在我的本地设置上运行。我使用默认配置在系统本地启动了 rabbitmq 服务器:用户:guest,密码:guest 和默认端口 5672。

我从 http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html 中选取了示例代码

from celery import Celery

app = Celery('tasks', broker='amqp://guest:guest@localhost:5672/hello')

@app.task
def add(x, y):
return x + y

所有这些都已完成并放置在 virtualenv 中。然后我在包含 app.py 文件的文件夹位置并使用命令:celery -A tasks worker --loglevel=info 从终端运行 celery worker。执行命令后得到如下输出:

Traceback (most recent call last):
File "/usr/local/bin/celery", line 11, in <module>
sys.exit(main())
File "/Library/Python/2.7/site-packages/celery/__main__.py", line 13, in main
from celery.bin.celery import main as _main
File "/Library/Python/2.7/site-packages/celery/bin/__init__.py", line 2, in <module>
from .base import Option
File "/Library/Python/2.7/site-packages/celery/bin/base.py", line 17, in <module>
from celery import VERSION_BANNER, Celery, maybe_patch_concurrency
File "/Library/Python/2.7/site-packages/celery/local.py", line 509, in __getattr__
module = __import__(self._object_origins[name], None, None, [name])
File "/Library/Python/2.7/site-packages/celery/app/__init__.py", line 5, in <module>
from celery import _state
File "/Library/Python/2.7/site-packages/celery/_state.py", line 15, in <module>
from celery.utils.threads import LocalStack
File "/Library/Python/2.7/site-packages/celery/utils/__init__.py", line 9, in <module>
from .functional import memoize # noqa
File "/Library/Python/2.7/site-packages/celery/utils/functional.py", line 11, in <module>
from kombu.utils.functional import (
ImportError: cannot import name LRUCache

使用的依赖项:amqp 2.2.2、billiard 3.5.0.3、celery 4.1.0、kombu 4.1.0、python 3.6

如果需要任何其他详细信息,请告诉我错误

最佳答案

运行 celery worker 的当前命令是:

celery -A app worker --loglevel=info

前提是你的worker文件名为app.py

关于 python celery 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48459238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com