tasks.py :
import time from celery import Celery broker = 'redis://:123456@localhost:6379/1' backend= 'redis://:123456@localhost:6379/2' #存储结果 app = Celery('my_task', broker = broker, backend=backend ) @app.task def add(x,y): print('enter call func......') time.sleep(4) return x+y
app.py
if __name__ == '__main__': print('start task...') result = add.delay(2,8) print("end task...") print result
需要主动执行app文件