我有以下文件夹: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 library@app.taskdef 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 我不知道我能做什么。有任何想法吗?
添加回答
举报
0/150
提交
取消