启动Celery:AttributeError:'模块'对象没有属性'celery' [英] Starting Celery: AttributeError: 'module' object has no attribute 'celery'

查看:204
本文介绍了启动Celery:AttributeError:'模块'对象没有属性'celery'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从命令行启动Celery Worker服务器:

I try to start a Celery worker server from a command line:

celery -A tasks worker --loglevel=info

tasks.py中的代码:

The code in tasks.py:

import os
os.environ[ 'DJANGO_SETTINGS_MODULE' ] = "proj.settings"

from celery import task

@task()
def add_photos_task( lad_id ):
...

我收到下一个错误:

Traceback (most recent call last):
  File "/usr/local/bin/celery", line 8, in <module>
    load_entry_point('celery==3.0.12', 'console_scripts', 'celery')()
  File "/usr/local/lib/python2.7/site-packages/celery-3.0.12-py2.7.egg/celery/__main__.py", line 14, in main
    main()
  File "/usr/local/lib/python2.7/site-packages/celery-3.0.12-py2.7.egg/celery/bin/celery.py", line 946, in main
    cmd.execute_from_commandline(argv)
  File "/usr/local/lib/python2.7/site-packages/celery-3.0.12-py2.7.egg/celery/bin/celery.py", line 890, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/usr/local/lib/python2.7/site-packages/celery-3.0.12-py2.7.egg/celery/bin/base.py", line 177, in execute_from_commandline
    argv = self.setup_app_from_commandline(argv)
  File "/usr/local/lib/python2.7/site-packages/celery-3.0.12-py2.7.egg/celery/bin/base.py", line 295, in setup_app_from_commandline
    self.app = self.find_app(app)
  File "/usr/local/lib/python2.7/site-packages/celery-3.0.12-py2.7.egg/celery/bin/base.py", line 313, in find_app
    return sym.celery
AttributeError: 'module' object has no attribute 'celery'

有人知道为什么找不到'celery'属性吗?谢谢您的帮助。

Does anybody know why the 'celery' attribute cannot be found? Thank you for help.

操作系统是Linux Debian 5。

The operating system is Linux Debian 5.

编辑 >。可能是线索。谁能解释给我一个函数的下一个注释(为什么我们必须确保它能在当前目录中找到模块)?

Edit. May be the clue. Could anyone explain me the next comment to a function (why we must be sure that it finds modules in the current directory)?

# from celery/utils/imports.py
def import_from_cwd(module, imp=None, package=None):
    """Import module, but make sure it finds modules
    located in the current directory.

    Modules located in the current directory has
    precedence over modules located in `sys.path`.
    """
    if imp is None:
        imp = importlib.import_module
    with cwd_in_path():
        return imp(module, package=package)


推荐答案

我忘了在task.py中创建一个芹菜对象:

I forgot to create a celery object in tasks.py:

from celery import Celery
from celery import task  

celery = Celery('tasks', broker='amqp://guest@localhost//') #!

import os

os.environ[ 'DJANGO_SETTINGS_MODULE' ] = "proj.settings"

@task()
def add_photos_task( lad_id ):
...

之后,我们通常可以开始执行任务:

After that we could normally start tasks:

celery -A tasks worker --loglevel=info

这篇关于启动Celery:AttributeError:'模块'对象没有属性'celery'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆