0
0
Flaskframework~20 mins

Task queue concept in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Task Queue Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a Flask app uses a task queue?

Consider a Flask app that delegates long-running tasks to a task queue like Celery. What is the main benefit of this approach?

AThe Flask app will run tasks faster by using multiple CPU cores automatically.
BThe Flask app can respond quickly to user requests without waiting for the task to finish.
CThe Flask app will store all task results in the browser cache for faster access.
DThe Flask app will block user requests until the task queue finishes all tasks.
Attempts:
2 left
💡 Hint

Think about how task queues help with long tasks and user experience.

📝 Syntax
intermediate
2:00remaining
Which code snippet correctly sends a task to a Celery queue in Flask?

Given a Celery instance named celery and a task function add, which code sends the task asynchronously?

Flask
from celery import Celery
celery = Celery('app')

@celery.task
def add(x, y):
    return x + y
Aadd.delay(4, 6)
Badd.run(4, 6)
Cadd.apply(4, 6)
Dadd.call(4, 6)
Attempts:
2 left
💡 Hint

Look for the method that queues the task for background execution.

state_output
advanced
2:00remaining
What is the output of this Flask + Celery task status check?

Assume a Celery task was sent with result = add.delay(2, 3). What will result.ready() return immediately after sending?

Flask
result = add.delay(2, 3)
print(result.ready())
AFalse
BTrue
CNone
DRaises AttributeError
Attempts:
2 left
💡 Hint

Think about whether the task finishes instantly or not.

🔧 Debug
advanced
2:00remaining
Why does this Flask + Celery task never complete?

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))
AThe task function multiply has a syntax error.
BThe get method does not accept a timeout argument.
CThe delay method is not valid for Celery tasks.
DNo Celery worker process is running to execute the task.
Attempts:
2 left
💡 Hint

Check if the background worker is active to process tasks.

🧠 Conceptual
expert
2:00remaining
Which statement best describes task queues in Flask apps?

Choose the most accurate description of how task queues improve Flask app design.

AThey replace Flask's routing system to manage HTTP requests more efficiently.
BThey automatically convert Flask apps into multi-threaded servers without extra configuration.
CThey allow Flask apps to handle heavy or slow tasks asynchronously, improving user experience and scalability.
DThey store all user session data in a centralized queue for faster retrieval.
Attempts:
2 left
💡 Hint

Think about the role of background processing in web apps.