Bird
0
0

Consider this Flask route:

medium📝 component behavior Q5 of 15
Flask - Performance Optimization
Consider this Flask route:
@app.route('/wait')
def wait():
    import time
    time.sleep(4)
    return 'Finished'

What will happen when users access '/wait'?
AThe response will be cached automatically
BUsers will get an immediate response
CThe server will crash due to the sleep call
DUsers will experience a 4-second delay before receiving the response
Step-by-Step Solution
Solution:
  1. Step 1: Analyze time.sleep()

    The function pauses execution for 4 seconds.
  2. Step 2: Understand response timing

    The route returns only after the delay, causing user wait.
  3. Final Answer:

    Users will experience a 4-second delay before receiving the response -> Option D
  4. Quick Check:

    time.sleep delays response [OK]
Quick Trick: time.sleep pauses route execution causing delay [OK]
Common Mistakes:
MISTAKES
  • Assuming immediate response despite sleep
  • Believing server crashes on sleep
  • Thinking caching happens automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes