无法启动 Celery worker 实例:语法错误
Unable to Start Celery worker instance : Syntax error
我正在尝试 运行 在 Django 视图中异步执行任务。为此,我正在使用 celery 和 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]
请帮忙,我无法确定我是否遗漏了配置步骤或版本问题。此外,如果有人可以验证这些步骤是否正确,以便使用 celery 在模块级别执行异步任务。谢谢!
嗯,这是 Celery. Celery does not support python 3.7 yet. Same goes to Kombu. So downgrade python to 3.6 or former. You can check the status of that issue at https://github.com/celery/celery/issues/4500
的一个已知问题
结果后端代码存在冲突。快速修复是禁用结果支持设置,例如
# CELERY_RESULT_BACKEND = 'redis://redis'
问题是因为您使用的是 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
我正在尝试 运行 在 Django 视图中异步执行任务。为此,我正在使用 celery 和 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]
请帮忙,我无法确定我是否遗漏了配置步骤或版本问题。此外,如果有人可以验证这些步骤是否正确,以便使用 celery 在模块级别执行异步任务。谢谢!
嗯,这是 Celery. Celery does not support python 3.7 yet. Same goes to Kombu. So downgrade python to 3.6 or former. You can check the status of that issue at https://github.com/celery/celery/issues/4500
的一个已知问题结果后端代码存在冲突。快速修复是禁用结果支持设置,例如
# CELERY_RESULT_BACKEND = 'redis://redis'
问题是因为您使用的是 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