将n个任务添加到芹菜队列中,等待结果 [英] Add n tasks to celery queue and wait for the results
本文介绍了将n个任务添加到芹菜队列中,等待结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码示例
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个任务添加到芹菜队列中,等待结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文