Consider a Flask app that delegates long-running tasks to a task queue like Celery. What is the main benefit of this approach?
Think about how task queues help with long tasks and user experience.
Using a task queue lets the Flask app hand off long tasks to a background worker. This way, the app can quickly reply to users without waiting for the task to complete.
Given a Celery instance named celery and a task function add, which code sends the task asynchronously?
from celery import Celery celery = Celery('app') @celery.task def add(x, y): return x + y
Look for the method that queues the task for background execution.
The delay method sends the task to the queue asynchronously. Other methods either run synchronously or do not exist.
Assume a Celery task was sent with result = add.delay(2, 3). What will result.ready() return immediately after sending?
result = add.delay(2, 3) print(result.ready())
Think about whether the task finishes instantly or not.
Immediately after sending, the task is usually not done, so ready() returns False.
Given this code, the task never finishes. What is the likely cause?
from celery import Celery
celery = Celery('app')
@celery.task
def multiply(x, y):
return x * y
result = multiply.delay(5, 7)
print(result.get(timeout=1))Check if the background worker is active to process tasks.
Without a running Celery worker, tasks stay queued and never execute, so get() waits until timeout.
Choose the most accurate description of how task queues improve Flask app design.
Think about the role of background processing in web apps.
Task queues let Flask apps offload slow tasks to workers, so the app stays responsive and can scale better.