Skip to content

Commit 57988b3

Browse files
committed
update celery
1 parent 74a2d52 commit 57988b3

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

python_celery.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
"""
44
测试celery
5-
运行:celery -A celery1:app worker -l INFO
5+
终端运行:celery -A python_celery:app worker -l INFO
66
"""
77

88
import time
9+
910
from celery import Celery
1011

11-
broker = 'redis://152.136.149.221:9002/10' # 用redis做broker,中间件
12-
backend = 'redis://152.136.149.221:9002/11' # 用redis做broken,用来保存结果
12+
broker = "redis://localhost:6379/10" # 用redis做broker,中间件
13+
backend = "redis://localhost:6379/11" # 用redis做broken,用来保存结果
14+
15+
app = Celery("tasks", broker=broker, backend=backend)
1316

14-
app = Celery('tasks',broker=broker,backend=backend)
1517

1618
@app.task
1719
def add(x, y):

python_celery_test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
"""
66

77
import time
8+
89
from python_celery import add
910

1011
if __name__ == "__main__":
1112
result = []
1213
for i in range(10):
13-
result.append(add.delay(1, 2))
14+
result.append(add.delay(i, i))
15+
print("----", time.time())
16+
for index, item in enumerate(result):
17+
print(index, item.get())
1418
print("----", time.time())
15-
for i in result:
16-
print(i, i.get())
17-
print("----", time.time())

0 commit comments

Comments
 (0)