找不到芹菜名字

时间:2018-09-12 06:43:43

标签: python celery

我正在尝试设置芹菜并出现以下错误。

    (ENV) E:\src\credixo\test>python celeryexperiments\driver.py
Traceback (most recent call last):
  File "celeryexperiments\driver.py", line 1, in <module>
    from alltasks.widget1 import download
  File "E:\src\credixo\test\celeryexperiments\alltasks\widget1.py", line 1, in <module>
    from celery import task
  File "E:\src\credixo\test\celeryexperiments\celery.py", line 1, in <module>
    from celery import Celery
ImportError: cannot import name 'Celery'

以下是我的目录结构。

celeryexperiments
   +__init__.py
   +celery.py
   +driver.py
   +alltasks
       +__init__.py
       +widget1.py

以下是内容。 1. driver.py

from alltasks.widget1 import download
download.delay('google.com')

2。 celery.py

from celery import Celery

app = Celery('celeryexperiments')
app.conf.update(
    BROKER_URL='redis://127.0.0.1:6379',
    CELERY_RESULT_BACKEND='redis://127.0.0.1:6379',
    CELERY_ENABLE_UTC=False,
    CELERY_ACCEPT_CONTENT=['application/json'],
    CELERY_TASK_SERIALIZER='json',
    CELERY_RESULT_SERIALIZER='json',
    CELERY_TIMEZONE='Asia/Kolkata'
)
app.autodiscover_tasks(['celeryexperiments.alltasks.widget1'])

3。 widget1.py 从芹菜导入任务中

@task(name="download", ignore_result=False, bind=True)
def download(self, url):
    print('{0} is downloaded'.format(url))

芹菜工人正常启动。

1 个答案:

答案 0 :(得分:2)

问题在于您的文件名为submit(...)。这将隐藏List<Integer> result = pool.submit(() -> testList.parallelStream().map(item -> { try { // read from database Thread.sleep(1000); System.out.println("task" + item + ":" + Thread.currentThread()); } catch (Exception e) { } return item * 10; }).collect(Collectors.toList())).get(); 库。重命名模块,该错误应该消失(假设您已安装celery)。