Celery实现异步任务
celery==3.1.25
rabbitmq开启服务
tasks.py代码如下:
1 from celery import Celery 2 3 broker = 'amqp://guest:guest@localhost:5672//' 4 backend = 'amqp' 5 6 app = Celery('tasks', broker=broker, backend=backend) 7 8 9 @app.task 10 def add(x, y): 11 return x + y
在文件同级目录下键入命令:
celery -A tasks worker --loglevel=info
开启新终端,调用如下: