Running a task after all tasks have been completed

后端 未结 4 1989
迷失自我
迷失自我 2020-12-29 09:21

I\'m writing an application which needs to run a series of tasks in parallel and then a single task with the results of all the tasks run:

@celery.task
def p         


        
4条回答
  •  别那么骄傲
    2020-12-29 09:42

    The answer that @alexander-afanasiev gave you is essentially right: use a chord.

    Your code is OK, but tasks.append(power.s((i, 2))) is not actually executing the subtask, just adding subtasks to a list. It's chord(...)(...) the one that send as many messages to the broker as subtasks you have defined in tasks list, plus one more message for the callback subtask. When you call chord it returns as soon as it can.

    If you want to know when the chord has finished you can poll for completion like with a single task using r.ready() in your sample.

提交回复
热议问题