Bird
0
0

Identify the error in this Celery task code:

medium📝 Debug Q7 of 15
Flask - Background Tasks
Identify the error in this Celery task code:
@celery_app.task
def divide(x, y):
    return x / y

result = divide.delay(10, 0).get()
AThe task must return a string, not a number.
BThe <code>delay</code> method is not valid for Celery tasks.
CDivision by zero will raise an exception during task execution.
DThe decorator <code>@celery_app.task</code> is missing parentheses.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze task logic

    The task divides x by y. Here, y is zero.
  2. Step 2: Understand runtime error

    Division by zero causes a runtime exception when the task runs asynchronously.
  3. Final Answer:

    Division by zero will raise an exception during task execution. -> Option C
  4. Quick Check:

    Division by zero in task causes runtime error [OK]
Quick Trick: Check for runtime errors like division by zero in tasks [OK]
Common Mistakes:
MISTAKES
  • Thinking delay is invalid
  • Assuming tasks must return strings
  • Confusing decorator syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes