python - 无法启动工人,没有名为“芹菜”的模块
问题描述
我尝试在我的 web 应用程序中包含任务,但我无法启动 celery 工作。
我的项目结构如下:
网站/网站 --> init.py、settings.py、urls.py、wsgi.py
网站/索引 --> init.py、celery_app.py、tasks.py
索引是我要运行任务的起始页。
index/celery_app.py有以下代码:
from __future__ import absolute_import, unicode_literals
from celery import Celery
app = Celery('index',
broker='amqp://localhost//',
backend='amqp://',
include=['index.tasks'])
# Optional configuration, see the application user guide.
app.conf.update(
result_expires=3600,
)
if __name__ == '__main__':
app.start()
索引/tasks.py:
from __future__ import absolute_import
from .celery_app import app
@app.task
def test_func():
print("Test Background Task")
当我想用celery -A index worker --loglevel=info启动 worker 时,我收到以下错误:ModuleNotFoundError: No module named 'celery'。我在索引文件夹中运行命令提示符。
类似问题中的其他解决方案对我没有帮助。
解决方案
只写
app = Celery(
"SARyS",
broker='pyamqp://guest:guest@rabbitmq.insertmendoza.com.ar',
include=["SARyS.Apps.TaskManager.Tasks"]
)
推荐阅读
- pytorch - 为什么 VAE 损失不会收敛到零?
- azure - 将图片从 azure IoT-hub 导入到 Xamarin 应用程序
- sharepoint-2013 - 抱歉,出了点问题 此页面上不允许使用控件类型“Microsoft.PerformancePoint.Scorecards.TransformerConfigurationRecord”
- c++ - 如何在每个 while 循环中初始化 rapidjson 缓冲区?
- java - 我们可以在服务类中使用 restTemplate 而不是在 Spring Boot 中使用控制器类吗?如果可能,请提供一个例子
- django - 在模板中获取 url 时出错 - Django
- html - 使用 flex 时,铬合金中会出现左侧填充;但不是在Firefox中
- javascript - 如何使用 Javascript 来验证我是否已禁用或授予正确的同意?
- java - 如何在 Spring Web Flux 基本身份验证(反应式编程)中为特定 URL 添加 CSRF 禁用
- javascript - Firestore:如何通过存在于其他集合中来过滤文档?