【问题标题】:python celery not working蟒蛇芹菜不工作
【发布时间】:2018-07-05 16:02:02
【问题描述】:

我是 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、台球 3.5.0.3、芹菜 4.1.0、kombu 4.1.0、python 3.6

让我知道错误以及是否需要任何其他详细信息

【问题讨论】:

    标签: python celery


    【解决方案1】:

    试试这个:

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

    另外(即使我认为它与您的错误无关)您说您使用的是 python 3.6,但在错误跟踪中它看起来像是 2.7 版。

    【讨论】:

      【解决方案2】:

      尝试安装开发版 Billiard 和 Kombu:

      pip install -e git+https://github.com/celery/billiard.git#egg=billiard
      pip install -e git+https://github.com/celery/kombu.git#egg=kombu
      

      【讨论】:

        【解决方案3】:

        当前运行 celery worker 的命令是:

        celery -A app worker --loglevel=info
        

        如果您的工作文件名为 app.py

        【讨论】:

          猜你喜欢
          • 2018-01-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-11-11
          • 1970-01-01
          • 1970-01-01
          • 2015-06-01
          • 2018-09-09
          相关资源
          最近更新 更多