forked from xianhu/LearnPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_celery.py
More file actions
23 lines (16 loc) · 476 Bytes
/
Copy pathpython_celery.py
File metadata and controls
23 lines (16 loc) · 476 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# _*_ coding: utf-8 _*_
"""
测试celery
终端运行:celery -A python_celery:app worker -l INFO
"""
import time
from celery import Celery
broker = "redis://localhost:6379/10" # 用redis做broker,中间件
backend = "redis://localhost:6379/11" # 用redis做broken,用来保存结果
app = Celery("tasks", broker=broker, backend=backend)
@app.task
def add(x, y):
print(time.time(), x, y)
time.sleep(3)
print(time.time(), x, y, "--")
return x + y