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.
Start the group in the background:
Wait:
Task.delay
returnsAsyncResult
. UseAsyncResult.get
to get result of each task.To do that you need to keep references to the tasks.
Or you can use
ResultSet
:UPDATE:
ResultSet
is deprecated, please see @laffuste 's answer.I have a hunch you are not really wanting the delay but the async feature of Celery.
I think you really want a TaskSet: