- 标题:windows使用celery报错celery.exceptions.TimeoutError: The operation timed out.-CSDN博客
- 链接:https://blog.csdn.net/XFIRR/article/details/138466238
内容:
今天研究这个也弄了比较久,最开始是没有往系统这个方向上去想。后来发现在windows上启动的方式和mac和linux这种不一样。
下面放上完整的启动方式和初步使用:
1、安装redis
redis的安装就不写了,最后只要能启动redis就行。ping一下看看有没有pong就知道是否启动成功。
2、安装eventlet
只有在windows系统上需要安装这个,用于启动
pip install eventlet
3、安装celery
下载依赖
pip install "celery[redis,auth,msgpack]"
启动celery
celery -A tasks(你自己的项目名) worker -P eventlet -l info
4、安装flower(用于监控)
下载依赖
pip install flower
启动服务
celery -A tasks flower
访问网址
[http://localhost:5555/](http://localhost:5555/)
5、初步使用
celery_proj/tasks.py:
from celery import Celery
app = Celery("tasks", backend='redis://127.0.0.1:6379/', broker='redis://127.0.0.1:6379/')
@app.task
def add(x, y):
return x + y
@app.task
def simple_task():
return "Hello, World!"
celery_proj/run_tasks.py:
from tasks import add, simple_task
result = add.delay(4, 3)
print(result.get(timeout=1))
运行run_tasks:
python run_tasks.py
最终的结果:
因为运行的是add,最后结果应该为7