亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我不能使用芹菜任務

我不能使用芹菜任務

滄海一幻覺 2021-08-11 16:42:58
我有以下文件夾:proj ├── __init__.py ├── celery.py ├── tasks.py ├── foo_launcher.py首先,我必須啟動 celery worker。celery -A proj worker -l infocelery.py 代碼:from __future__ import absolute_import, unicode_literalsfrom celery import Celeryapp = Celery('project', broker='amqp://guest@localhost//', include=['project.tasks'])if __name__ == '__main__':   app.start()Celery worker 工作正常,但是當我要啟動時foo_launcher.py,我無法使用這些任務,因為foo_launcher.py取決于tasks.py和tasks.py取決于celery.py. 這是問題所在。我需要導入 celery.py 文件而不是 celery 庫。所以,這是 tasks.pyfrom  .celery import app #Here Import celery.py not celery [email protected] add(x, y):   return x + y和這里 foo_launcher.pyfrom tasks import addresult = add.apply_async((2,2), queue='lopri',coutdown=10)print(result)顯然一切都有意義,但是當我嘗試啟動時foo_launcher.py:python foo_launcher.py它向我發起了以下錯誤:Traceback (most recent call last):    File ".\foo_launcher.py", line 1, in <module>        from tasks import add    File "C:\Users\beca4\Desktop\proj\tasks.py", line 1, in <module>             from  .celery import app                                                                                           ImportError: attempted relative import with no known parent package   我不知道我能做什么。有任何想法嗎?
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號