最终与该项目布局一起工作
proj/celery_proj/__init__.py /celery.py /tasks.py /test.py
哪里
芹菜
from __future__ import absolute_importfrom celery import Celeryapp = Celery('celery_proj', broker='amqp://', backend='amqp://', include=['celery_proj.tasks'])# Optional configuration, see the application user guide.app.conf.update( CELERY_TASK_RESULT_EXPIRES=3600,)if __name__ == '__main__': app.start()
task.py
from __future__ import absolute_importfrom celery_proj.celery import app@app.taskdef add(x, y): return x + y@app.taskdef mul(x, y): return x * y@app.taskdef xsum(numbers): return sum(numbers)
test.py
__author__ = 'mehdi'path = '/home/mehdi/PycharmProjects'import syssys.path.append(path)from celery_proj.tasks import addr = add.delay(4,4)print(r.status)print(r.result)
并通过以下方式启动工作人员:
cd projcelery -A celery_proj worker -l info
然后运行test.py:
python test.py
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)