gpt4 book ai didi

python - 使用依赖图执行 Celery 任务

转载 作者:太空狗 更新时间:2023-10-29 20:13:05 27 4
gpt4 key购买 nike

我希望 Celery 任务依赖于 2 个或更多其他任务的结果。我调查了Python+Celery: Chaining jobs?http://pypi.python.org/pypi/celery-tasktree ,但只有当任务只有一个依赖任务时,这些才是好的。

我知道 TaskSet,但似乎没有办法在 TaskSetResult.ready() 变为 True 时立即执行回调。我现在想到的是有一个周期性任务,每隔几 [毫秒] 秒左右轮询一次 TaskSetResult.ready() 并在回调返回 True 时触发回调,但这对我来说听起来很不雅观。

有什么建议吗?

最佳答案

在最新版本的 Celery (3.0+) 中,您可以使用所谓的和弦来达到所需的效果:

来自 http://docs.celeryproject.org/en/latest/userguide/canvas.html#the-primitives :

Simple chord

The chord primitive enables us to add callback to be called when all of the tasks in a group have finished executing, which is often required for algorithms that aren't embarrassingly parallel:

 >>> from celery import chord
>>> res = chord((add.s(i, i) for i in xrange(10)), xsum.s())()
>>> res.get()
90

免责声明:我自己还没有尝试过。

关于python - 使用依赖图执行 Celery 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6580649/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com