将n个任务添加到芹菜队列中,等待结果

编程入门 行业动态 更新时间:2024-10-25 04:17:15
本文介绍了将n个任务添加到芹菜队列中,等待结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我将添加多个任务到芹菜队列并等待结果。我有各种各样的想法,我将如何实现这一点使用某种形式的共享存储(memcached,redis,db等),但是,我认为这是Celery可以自动处理,但我找不到任何在线资源。 / p>

代码示例

def do_tasks b): for a in b: c.delay(a) return c.all_results_some_how()

解决方案

对于 Celery> = 3.0 ,TaskSet是已弃用,赞成组。

从芹菜进口组从任务导入添加 job = group([ add.s(2,2), add.s(4,4), add.s(8,8), add.s(16,16), add.s(32,32), ])

等待:

result = job.apply_async() result.join()

I would add multiple tasks to celery queue and wait for results. I have various ideas how I would achieve this utilising some form of shared storage (memcached, redis, db, etc.), however, I would have thought it's something that Celery can handle automatically but I can't find any resources online.

Code example

def do_tasks(b): for a in b: c.delay(a) return c.all_results_some_how()

解决方案

For Celery >= 3.0, TaskSet is deprecated in favour of group.

from celery import group from tasks import add job = group([ add.s(2, 2), add.s(4, 4), add.s(8, 8), add.s(16, 16), add.s(32, 32), ])

Wait:

result = job.apply_async() result.join()

更多推荐

将n个任务添加到芹菜队列中,等待结果

本文发布于:2023-11-24 05:35:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624123.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:队列   芹菜

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!