Bird
0
0

Given the following code, what will be the output when add.delay(4, 5) is called?

medium📝 component behavior Q13 of 15
Flask - Background Tasks
Given the following code, what will be the output when add.delay(4, 5) is called?
from celery import Celery
celery_app = Celery('tasks')

@celery_app.task
def add(x, y):
    return x + y

result = add.delay(4, 5)
print(type(result))
A<class 'celery.result.AsyncResult'>
B<class 'int'>
C9
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Understand what delay() returns

    The delay() method queues the task and returns an AsyncResult object, not the actual result.
  2. Step 2: Check the printed type

    Printing type(result) shows the class of the returned object, which is celery.result.AsyncResult.
  3. Final Answer:

    <class 'celery.result.AsyncResult'> -> Option A
  4. Quick Check:

    delay() returns AsyncResult object [OK]
Quick Trick: delay() returns AsyncResult, not the task output [OK]
Common Mistakes:
MISTAKES
  • Expecting delay() to return the task result immediately
  • Confusing AsyncResult with the actual return value
  • Printing result instead of type(result)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes