Bird
0
0

Given this task definition:

medium📝 component behavior Q13 of 15
Django - Celery and Background Tasks
Given this task definition:
from celery import shared_task

@shared_task
def add(x, y):
    return x + y

result = add.delay(4, 5)

What will result.get() return?
A9
BNone
CAn AsyncResult object
DA syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the task and its call

    The add function adds two numbers. Calling add.delay(4, 5) runs it asynchronously and returns an AsyncResult.
  2. Step 2: Using result.get() retrieves the task result

    Calling result.get() waits for the task to finish and returns the sum, which is 9.
  3. Final Answer:

    9 -> Option A
  4. Quick Check:

    Task result = 9 [OK]
Quick Trick: delay() returns AsyncResult; get() fetches the actual result [OK]
Common Mistakes:
MISTAKES
  • Thinking delay() returns the result immediately
  • Confusing AsyncResult object with the actual result
  • Expecting None because task runs asynchronously

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes