Running a task after all tasks have been completed

后端 未结 4 2003
迷失自我
迷失自我 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:56

    Taking a look at this snippet from your question, it looks like you are passing a list as the chord header, rather than a group:

    from time import sleep
    import random
    
    tasks = []
    
    for i in xrange(10):
        tasks.append(power.s((i, 2)))
        sleep(random.randint(10, 1000) / 1000.0) # sleep for 10-1000ms
    
    callback = amass.s()
    
    r = chord(tasks)(callback)
    

    Converting the list to a group should result in the behaviour you're expecting:

    ...
    
    callback = amass.s()
    
    tasks = group(tasks)
    
    r = chord(tasks)(callback)
    

提交回复
热议问题