python芹菜的值无效-无法加载应用程序
我有以下项目目录:python芹菜的值无效-无法加载应用程序,python,celery,celery-task,Python,Celery,Celery Task,我有以下项目目录: azima: __init.py main.py tasks.py task.py from .main import app @app.task def add(x, y): return x + y @app.task def mul(x, y): return x * y @app.task def xsum(numbers): return sum(numbers) main.py from celery im
azima:
__init.py
main.py
tasks.py
task.py
from .main import app
@app.task
def add(x, y):
return x + y
@app.task
def mul(x, y):
return x * y
@app.task
def xsum(numbers):
return sum(numbers)
main.py
from celery import Celery
app = Celery('azima', backend='redis://localhost:6379/0', broker='redis://localhost:6379/0', include=['azima.tasks'])
# Optional configuration, see the application user guide.
app.conf.update(
result_expires=3600,
)
if __name__ == '__main__':
app.start()
当我运行命令初始化芹菜工人时,出现以下错误:
(azima_venv) brightseid@darkseid:~$ celery -A azima worker -l INFO
Usage: celery [OPTIONS] COMMAND [ARGS]...
Error: Invalid value for '-A' / '--app':
Unable to load celery application.
Module 'azima' has no attribute 'celery'
但是,当我将main.py
重新命名为cellery.py
时,就没有问题了
我在这里遗漏了什么?有两种方法
app
导入到azima/\uuuuu init\uuuuu.py
来自azima.main导入应用程序
芹菜=app#你可以省略这一行
您可以省略最后一行,芹菜将从导入中识别芹菜应用程序。然后你打电话给芹菜-阿齐玛工人-l信息
芹菜-A azima.main worker-l INFO