简体   繁体   中英

How do I run parallel tasks with Celery?

I am using Celery to run some tasks that take a long time to complete. There is an initial task that needs to complete before two sub-tasks can run. The tasks that I created are file system operations and don't return a result.

I would like the subtasks to run at the same time, but when I use a group for these tasks they run sequentially and not in parallel.

I have tried:

g = group([secondary_task(), secondary_tasks2()])
chain(initial_task(),g)

I've also tried running the group directly in the first task, but that doesn't seem to work either.

Is what I'm trying to accomplish doable with Celery?

    First Task
/                \
Second Task      Third Task

Not:

First Task
     |
Second Task
     | 
Third Task

The chain is definitely the right approach.

I would expect this to work: chain(initial_task.s(), g)()

Do you have more than one celery worker running to be able to run more than one task at the same time?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM