Bird
0
0

Given this code snippet in a Flask app with Celery:

medium📝 component behavior Q13 of 15
Flask - Background Tasks
Given this code snippet in a Flask app with Celery:
@celery_app.task
def multiply(x, y):
    return x * y

result = multiply.delay(3, 4)
print(result.get())
What will be printed?
AA task object reference
Bnull
C12
DAn error because delay() is not valid
Step-by-Step Solution
Solution:
  1. Step 1: Understand delay() usage

    Calling multiply.delay(3, 4) sends the task to Celery to run asynchronously.
  2. Step 2: Using get() to wait for result

    result.get() waits for the task to finish and returns the output, which is 3 * 4 = 12.
  3. Final Answer:

    12 -> Option C
  4. Quick Check:

    delay() runs task, get() returns result [OK]
Quick Trick: delay() runs task, get() fetches result [OK]
Common Mistakes:
MISTAKES
  • Thinking delay() returns the result immediately
  • Confusing task object with result value
  • Assuming delay() is invalid in Celery

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes