欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

celery + redis demo

程序员文章站 2022-04-08 16:07:01
...
  1. 环境准备
pip install -U celery[redis]

2.创建task

from celery import Celery
import time
app = Celery('test', backend='redis://localhost:6379/0', broker='redis://localhost:6379/0')

@app.task
def hello():
    time.sleep(10)
    return 'hello world'

@app.task
def fun():
    return 'fun'

3.创建worker

celery worker -A test --loglevel=debug

4.测试

from test import fun
if __name__ == '__main__':
    print fun.delay().get()