Here are the tasks:
from celery import shared_task
from celery import Celery
import time
celery = Celery("example_tasks", backend="rpc://", broker="amqp://")
@shared_task
def parent_task():
print("Starting parent task.")
for i in range(2):
result = child_task.delay(i)
@shared_task
def child_task(index):
time.sleep(5)
print(f"Starting child task {index}.")
Here is the main program:
from celery import Celery
import time
from example_tasks import parent_task
app = Celery("tasks", backend="rpc://", broker="amqp://")
result = parent_task.delay()
At the end of the main program, what is the best way to wait until all tasks (subtasks included) have finished?