Bird
0
0

Given this async Flask route, what will be the output when accessed?

medium📝 component behavior Q13 of 15
Flask - Ecosystem and Patterns
Given this async Flask route, what will be the output when accessed?
from flask import Flask
import asyncio
app = Flask(__name__)

@app.route('/')
async def home():
    await asyncio.sleep(0.1)
    return 'Done'
AThe route crashes because Flask does not support async.
BThe route returns immediately with 'Done'.
CThe route returns 'Done' after a short delay.
DThe route causes a syntax error due to await usage.
Step-by-Step Solution
Solution:
  1. Step 1: Understand async route behavior

    The route uses await asyncio.sleep(0.1) which pauses the function asynchronously for 0.1 seconds.
  2. Step 2: Predict output after await

    After the short async pause, the route returns the string 'Done'. So the client sees 'Done' after a slight delay.
  3. Final Answer:

    The route returns 'Done' after a short delay. -> Option C
  4. Quick Check:

    Await sleep delays then returns [OK]
Quick Trick: Await pauses async route before returning result [OK]
Common Mistakes:
MISTAKES
  • Thinking await causes syntax error
  • Expecting immediate return ignoring await
  • Assuming Flask can't run async routes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes