我按照 [ http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html ] 中给出的所有步骤进行操作 这是代码:
from __future__ import absolute_import
from celery import Celery
#app = Celery('tasks', broker='pyamqp://guest@localhost//')
app = Celery('tasks', backend='redis://localhost', broker='pyamqp://guest@localhost//')
@app.task
def add(x, y):
return x + y
当我使用以下命令运行 celery worker
celery -A tasks worker --loglevel=info
我收到设置后端的语法错误。这是错误消息:
[2018-07-10 16:37:21,970: CRITICAL/MainProcess] 不可恢复的错误:SyntaxError('invalid syntax', ('c:\users\user_\appdata\local\programs\python\python37-32\lib\site -packages\celery\backends\redis.py', 22, 19, 'from . import async, base\n')) Traceback(最近一次调用最后):文件“c:\users\user_\appdata\local\programs \python\python37-32\lib\site-packages\kombu\utils\objects.py”,第 42 行,在获取 返回 obj 中。dict [自我。姓名] KeyError: 'backend' 在处理上述异常的过程中,又发生了一个异常: Traceback (最近一次调用 last): File "c:\users\user_\appdata\local\programs\python\python37-32\lib\site- packages\celery\worker\worker.py”,第 205 行,在 start self.blueprint.start(self) 文件“c:\users\user_\appdata\local\programs\python\python37-32\lib\site-packages \celery\bootsteps.py”,第 115 行,在 start self.on_start() 文件中“c:\users\user_\appdata\local\programs\python\python37-32\lib\site-packages\celery\apps\worker .py”,第 139 行,在 on_start self.emit_banner() 文件“c:\users\user_\appdata\local\programs\python\python37-32\lib\site-packages\celery\apps\worker.py”中,第 154 行,在 emit_banner '\n',self.startup_info(artlines=not use_image))),文件“c:\users\user_\appdata\local\programs\python\python37-32\lib\site-packages\celery\apps\worker.py",第 217 行,在 startup_info 结果=self.app.backend.as_uri(),文件“c:\users\user_\appdata\local\programs\python\python37-32\lib\site-packages\kombu\utils\objects.py”,第 44 行,在获取 值 = obj。dict [自我。名称] =自我。获取(obj)文件“c:\users\user \appdata\local\programs\python\python37-32\lib\site-packages\celery\app\base.py”,第 1196 行,在后端返回 self。get_backend() 文件“c:\users\user \appdata\local\programs\python\python37-32\lib\site-packages\celery\app\base.py”,第 914 行,在get_backend self.loader) 文件中“ c:\users\user \appdata\local\programs\python\python37-32\lib\site-packages\celery\app\backends.py",第 70 行,在 by_url 返回 by_name(backend, loader),url 文件" c:\用户\用户\appdata\local\programs\python\python37-32\lib\site-packages\celery\app\backends.py”,第 50 行,在 by_name cls = symbol_by_name(backend, aliases) 文件“c:\users\user_\ appdata\local\programs\python\python37-32\lib\site-packages\kombu\utils\imports.py”,第 56 行,在 symbol_by_name 模块 = imp(module_name, package=package, **kwargs) 文件“c: \users\user_\appdata\local\programs\python\python37-32\lib\importlib_ init _.py",第 127 行,在 import_module 中返回 _bootstrap._gcd_import(name[level:], package, level) File "",第 1006 行,在 _gcd_import 文件“”中,第 983 行,在 _find_and_load 文件中“”,第 967 行,在 _find_and_load_unlocked 文件中“”,第 677 行,在 _load_unlocked 文件中“”,第 724 行,在 exec_module 文件中“”,第 860 行,在 get_code 文件“”中,第 791 行,在 source_to_code 文件中“”,第 219 行,在call_with_frames_removed 文件“c:\users\user \appdata\local\programs\python\python37-32\lib\site-packages\celery\backends\redis.py”,第 22 行来自 . 导入异步,基 ^ SyntaxError:无效语法
但是,当我使用注释行时,我没有任何问题,只是结果后端被禁用,我需要将结果后端设置为 redis-server