1.1 安装celery
pip install celery @ https://github.com/celery/celery/tarball/master
1.2 新建celery/main.py
配置celery
# celery_task/main.py import os from celery import Celery # 定义celery实例, 需要的参数, 1, 实例名, 2, 任务发布位置, 3, 结果保存位置 app = Celery('mycelery', broker='redis://127.0.0.1:6379/14', # 任务存放的地方 backend='redis://127.0.0.1:6379/15') # 结果存放的地方 @app.task def add(x, y): return x + ycelery/main.py
2.测试celery
2.1 启动celery
'''1.启动celery''' #1.1 单进程启动celery celery -A main worker -l INFO #1.2 celery管理 celery multi start celery_test -A celery_test -l debug --autoscale=50,5 # celery并发数:最多50个,最少5个 ps auxww|grep "celery worker"|grep -v grep|awk '{print $2}'|xargs kill -9 # 关闭所有celery进程celery