python - celery 不运行和弦回调

标签 python ubuntu celery

在看了很多关于和弦回调不执行的文章并尝试了他们的解决方案之后,我仍然无法让它工作。事实上,由于某种原因,chord_unlock 方法也没有被执行。

celery .py

from __future__ import absolute_import
from celery import Celery

app = Celery('sophie',
             broker='redis://localhost:6379/2',
             backend='redis://localhost:6379/2',
             include=['sophie.lib.chord_test'])

app.conf.update(
    CELERY_ACCEPT_CONTENT=["json"],
    CELERY_TASK_SERIALIZER="json",
    CELERY_TRACK_STARTED=True,
    CELERYD_PREFETCH_MULTIPLIER=1,   # NO PREFETCHING OF TASKS
    BROKER_TRANSPORT_OPTIONS = {
        'priority_steps': [0, 1]     # ALLOW ONLY 2 TASK PRIORITIES
    }
)

if __name__ == '__main__':
    app.start()

和弦测试.py

from __future__ import absolute_import
from sophie.celery import app
from celery import chord

@app.task(name='sophie.lib.add')
def add(x, y):
    return x + y

@app.task(name='sophie.lib.tsum')
def tsum(numbers):
    return sum(numbers)

if __name__ == '__main__':
    tasks = [add.s(100, 100), add.s(200, 200)]
    chord(tasks, tsum.s()).apply_async()

我的worker日志文件的输出如下

$ celery worker -l info --app=sophie.celery -n worker1.%h

 -------------- celery@worker1.vagrant-ubuntu-11 v3.1.6 (Cipater)
---- **** ----- 
--- * ***  * -- Linux-3.0.0-12-server-x86_64-with-Ubuntu-11.10-oneiric
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> broker:      redis://localhost:6379/2
- ** ---------- .> app:         sophie:0x3554250
- ** ---------- .> concurrency: 1 (prefork)
- *** --- * --- .> events:      OFF (enable -E to monitor this worker)
-- ******* ---- 
--- ***** ----- [queues]
 -------------- .> celery           exchange=celery(direct) key=celery


[tasks]
  . sophie.lib.add
  . sophie.lib.tsum

[2013-12-12 19:37:26,499: INFO/MainProcess] Connected to redis://localhost:6379/2
[2013-12-12 19:37:26,506: INFO/MainProcess] mingle: searching for neighbors
[2013-12-12 19:37:27,512: INFO/MainProcess] mingle: all alone
[2013-12-12 19:37:27,527: WARNING/MainProcess] celery@worker1.vagrant-ubuntu-11 ready.
[2013-12-12 19:37:29,723: INFO/MainProcess] Received task: sophie.lib.add[b7d504c1-217f-43a9-b57e-86f0fcbdbe22]
[2013-12-12 19:37:29,734: INFO/MainProcess] Task sophie.lib.add[b7d504c1-217f-43a9-b57e-86f0fcbdbe22] succeeded in 0.009769904
00522s: 200
[2013-12-12 19:37:29,735: INFO/MainProcess] Received task: sophie.lib.add[eb01a73e-f6c8-401d-8049-6cdbc5f0bd90]
[2013-12-12 19:37:29,737: INFO/MainProcess] Task sophie.lib.add[eb01a73e-f6c8-401d-8049-6cdbc5f0bd90] succeeded in 0.001446505
00442s: 400

根本没有调用 chord_unlock。更多输出以提供更多上下文:

$ sudo pip freeze | egrep 'celery|kombu|billiard'
billiard==3.3.0.12
celery==3.1.6
kombu==3.0.7

$ uname -a
Linux vagrant-ubuntu-11 3.0.0-12-server #20-Ubuntu SMP Fri Oct 7 16:36:30 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

$ redis-server --version
Redis server version 2.2.11 (00000000:0)

最佳答案

chords documentation和弦使用以下语法:

 result = chord(header)(callback)

所以你可以这样做:

 chord(tasks)(tsum.s())

关于python - celery 不运行和弦回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20546120/

相关文章:

python - 如何正确地将 MIDI 节拍转换为毫秒?

Python:将mxn数组旋转到任意角度

python - 如何准备 Ubuntu 14.04 以安装 Django

c++ - 安装旧版本的 gcc

Python 滚动文本模块

qt - 在 ubuntu 22.04 上启动 spyder 时出错

django - 如何在 Django 中跨应用程序/项目注册 celery 任务?

django - 为什么在启动 celery 时没有检测到我的环境变量?

python - 导入错误: No module named 'celery'

Python PyQt Pyside - QFileDialog 中的 setNameFilters 不起作用