Celery异步分布式
Celery是一个python开发的异步分布式任务调度模块
Celery本身并不提供消息服务,使用第三方服务,也就是borker来传递任务,目前支持rebbimq,redis, 数据库等
使用redis连接url的格式为:
redis://:[email protected]:port/db_number
例如:
BROKER_URL = 'redis://localhost:6379/0'
1)huang.py
from celery import Celery
broker = "redis://192.168.2.230:6379/1"
backend = "redis://192.168.2.230:6379/2"
app = Celery("huang",broker=broker,backend=backend)
@app.task
def add(x,y):
return x+y
2)安装celery:
pip install celery
pip install redis
启动:celery -A huang worker -l info
3)celery.py #调用
from test import add
re = add.delay(10,20)
print(re.result)
print(re.ready)
print(re.get(timeout=1))
print(re.status)
时间: 2024-10-08 23:35:25