tasks.py. What will be printed when the task is called asynchronously?from celery import shared_task @shared_task def add(x, y): return x + y result = add.delay(4, 5) print(result.ready())
delay() returns and when the task finishes.The delay() method queues the task and returns an AsyncResult immediately. The task is not finished yet, so result.ready() returns False.
result.get() after task completion?result.get() return after the task finishes?from celery import shared_task @shared_task def multiply(x, y): return x * y result = multiply.delay(3, 7) output = result.get(timeout=10) print(output)
get() method waits for the task result.The get() method blocks until the task completes or the timeout expires. Since the task multiplies 3 and 7, the result is 21.
celery.py or tasks.py?Option A uses crontab(minute='*/10') which correctly schedules the task every 10 minutes. Other options either use wrong keys or invalid schedule types.
send_email.delay() raise an error?from celery import shared_task @shared_task def send_email(to_address): print(f"Sending email to {to_address}") send_email.delay()
The send_email task requires one argument to_address. Calling delay() without arguments causes a TypeError.
Celery sends tasks to a message broker like RabbitMQ or Redis. Worker processes listen to the broker and execute tasks asynchronously, separate from the Django main process.
