Consider a Flask app using Celery for background tasks. When you call a task with .delay(), what is the immediate behavior?
from celery import Celery celery_app = Celery('tasks', broker='redis://localhost:6379/0') @celery_app.task def add(x, y): return x + y result = add.delay(4, 6)
Think about how Celery handles tasks asynchronously.
Calling .delay() sends the task to the Celery worker queue and returns immediately with an AsyncResult object. The task runs asynchronously in a separate worker process, not blocking the Flask app.
In a Flask app integrating Celery, you need to configure the broker URL. Which option correctly sets the broker URL?
Look for the official Celery configuration attribute for the broker URL.
The correct way to set the broker URL in Celery is by assigning the URL string to celery_app.conf.broker_url. Other options are invalid or do not exist.
Given the code below, what does result.ready() return immediately after add.delay(2, 3) is called?
from celery import Celery celery_app = Celery('tasks', broker='redis://localhost:6379/0') @celery_app.task def add(x, y): return x + y result = add.delay(2, 3) ready_state = result.ready()
Think about asynchronous task execution and when results become ready.
The result.ready() method returns False immediately after .delay() because the task is still queued or running asynchronously. It only returns True once the task finishes.
Examine the code below. Why will the Celery tasks never run?
from flask import Flask from celery import Celery app = Flask(__name__) celery = Celery(app.name, broker='redis://localhost:6379/0') @celery.task def multiply(x, y): return x * y @app.route('/start') def start_task(): multiply.delay(5, 6) return 'Task started'
Think about what runs Celery tasks in the background.
Celery tasks require a separate worker process running to consume and execute tasks from the broker queue. Without starting the Celery worker, tasks remain queued and never run.
In a Flask app using Celery, how are task results stored and retrieved after the task completes?
Consider how asynchronous systems keep track of results separately from the main app.
Celery uses a result backend like Redis, a database, or other supported stores to save task results. The Flask app can retrieve results asynchronously using the AsyncResult object linked to the task ID.