无法启动Celery worker实例:语法错误

问题描述 投票:0回答:3

我正在尝试在django视图中异步运行任务。为此,我使用芹菜和rabbitmq。通过遵循小规模上下文指南,我在模块(servicenow.py)中将任务定义为-

app = Celery('servicenow',broker='amqp://username:password@localhost:15672')
.
.
@app.task
def get_ITARAS_dump(self):
.
.
self.update_state(state='PROGRESS',meta={'current':i,'total':len(taskList)})

我的rabbitmq服务器正在brew服务中运行

Rabbitmq management on safari

此后,我尝试使用celery -A servicenow worker -l info然后我将错误消息显示为-

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/celery", line 11, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/__main__.py", line 30, in main
    main()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/celery.py", line 81, in main
    cmd.execute_from_commandline(argv)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/celery.py", line 793, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/base.py", line 311, in execute_from_commandline
    return self.handle_argv(self.prog_name, argv[1:])
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/celery.py", line 785, in handle_argv
    return self.execute(command, argv)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/celery.py", line 717, in execute
    ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/worker.py", line 179, in run_from_argv
    return self(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/base.py", line 274, in __call__
    ret = self.run(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/worker.py", line 194, in run
    pool_cls = (concurrency.get_implementation(pool_cls) or
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/concurrency/__init__.py", line 29, in get_implementation
    return symbol_by_name(cls, ALIASES)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kombu/utils/__init__.py", line 96, in symbol_by_name
    module = imp(module_name, package=package, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/concurrency/prefork.py", line 20, in <module>
    from celery.concurrency.base import BasePool
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/concurrency/base.py", line 21, in <module>
    from celery.utils import timer2
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/utils/timer2.py", line 19
    from kombu.async.timer import Entry, Timer as Schedule, to_timestamp, logger
                   ^
SyntaxError: invalid syntax

我认为这是版本问题,但根据要求我认为我是正确的

django-celery==3.2.2
  - celery [required: >=3.1.15,<4.0, installed: 3.1.26.post2]
    - billiard [required: >=3.3.0.23,<3.4, installed: 3.3.0.23]
    - kombu [required: >=3.0.37,<3.1, installed: 3.0.37]
      - amqp [required: >=1.4.9,<2.0, installed: 1.4.9]
      - anyjson [required: >=0.3.3, installed: 0.3.3]
    - pytz [required: >dev, installed: 2018.7]
  - django [required: >=1.8, installed: 2.1.3]
    - pytz [required: Any, installed: 2018.7]

[请帮助,我无法确定我是否缺少配置或版本问题的步骤。另外,如果有人可以验证这些步骤是否正确,以便在芹菜的模块级别执行异步任务。谢谢!

django rabbitmq celery
3个回答
3
投票

好吧,这是Celery的已知问题。 Celery还不支持python 3.7。 Kombu也一样。因此,将python降级到3.6或更早的版本。您可以在https://github.com/celery/celery/issues/4500

上查看该问题的状态

1
投票

结果后端代码存在冲突。快速解决方案是禁用结果支持的设置,例如

# CELERY_RESULT_BACKEND = 'redis://redis'

0
投票

问题是因为您使用的是python 3.7。将其降级到python 3.6将解决该错误。让Mac用户降级到python 3.6

$ brew unlink python
$ brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/e128fa1bce3377de32cbf11bd8e46f7334dfd7a6/Formula/python.rb
$ brew switch python 3.6.5
© www.soinside.com 2019 - 2024. All rights reserved.