python - 导入错误: No module named control

标签 python import celery

我有一个 celery 应用程序,我的文件如下:

  /fetcher.py
  /mirad
       celery.py
       fetcher_tasks.py

celery.py中我导入了fetcher_tasks.py 在 fetcher.py 中,我从 fetcher_tasks.py 调用一个任务 我想在 fetcher.py 中导入 celery.control 但我做不到,我该如何完成这项工作?

这是我的提取器代码的一部分:

from __future__ import absolute_import

import mirad.fetcher_tasks as tasks
from mirad.models.models import SourceModel
from mirad.settings import *
from mirad.celery.control import inspect


parse_feed_tasks = list()

def fetch():

        for source in SourceModel.objects(active=True):
            a = tasks.parse_feed.delay(source)

最佳答案

看起来您在项目中混合了 celery.py,该项目用于使用 celery 包启动 Celery 应用程序,您可以从中导入必要的函数。

您应该从 celery.task.control 包中导入 inspect 函数。

from __future__ import absolute_import

import mirad.fetcher_tasks as tasks
from mirad.models.models import SourceModel
from mirad.settings import *
from celery.task.control import inspect

parse_feed_tasks = list()

def fetch():

        for source in SourceModel.objects(active=True):
            a = tasks.parse_feed.delay(source)

关于python - 导入错误: No module named control,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24583373/

相关文章:

python - 使用 Python 向 API Prestashop 发送请求

java - 从字符串中分配 freemarker 中的命名空间

django - celery :WorkerLostError: worker 过早退出:信号 9 (SIGKILL)

python - 我可以在不使用 djcelery 的情况下将 Celery v4.0.2 与 Django v1.7.1 一起使用吗?

python - celery 与 djcelery

Python Groupby 语句

python - scrapy - 无法正确地将多个 URL 从 <p> 标签提取到项目列表中

java - 声明的包裹与预期的包裹不匹配

pdf - 从 pdf 文件导入/读取数据的最佳方法是什么?

python - 如何在Python中将音频文件输入的语音转换为文本