Add n tasks to celery queue and wait for the results

后端 未结 3 2184
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 10:21

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, e

3条回答
  •  执念已碎
    2020-12-05 11:08

    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),
    ])
    

    Start the group in the background:

    result = job.apply_async()
    

    Wait:

    result.join()
    

提交回复
热议问题