需要将任务分队列消费处理,比如将任务放入rabbitma/redis/数据库,消费任务后,将结果存储或者是直接返回显示等;
celery入门资料
http://docs.jinkan.org/docs/celery/
安装redis、rabbitmq。
pip install celery / python -m pip install redis -i https://pypi.tuna.tsinghua.edu.cn/simple 之后
# tasks.py
from celery import Celery
app = Celery(
'tasks', # 当前模块的名字
broker='amqp://admin:password@192.168.10.199:5672//', # 消息队列的url
backend='redis://:password@xx.xx.xx.x:6379/1'
)
@app.task
def add(x, y):
return x + y
启动:celery -A tasks worker --loglevel=info
test.py
from tasks import add
add.delay(4, 4)
python test.py