Bird
0
0

Given this Flask app snippet with profiling enabled, what will be the effect when you run it?

medium📝 component behavior Q13 of 15
Flask - Performance Optimization
Given this Flask app snippet with profiling enabled, what will be the effect when you run it?
from flask import Flask
from werkzeug.middleware.profiler import ProfilerMiddleware
app = Flask(__name__)
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[10])

@app.route('/')
def home():
    return 'Hello Profiling!'

if __name__ == '__main__':
    app.run()
AThe app runs but profiling is disabled silently
BThe app runs normally and prints profiling info for each request in console
CThe app crashes due to wrong middleware usage
DThe app returns profiling data as HTTP response
Step-by-Step Solution
Solution:
  1. Step 1: Analyze middleware wrapping

    ProfilerMiddleware wraps app.wsgi_app correctly with restrictions=[10].
  2. Step 2: Understand runtime behavior

    App runs normally and profiling info prints to console for each request.
  3. Final Answer:

    The app runs normally and prints profiling info for each request in console -> Option B
  4. Quick Check:

    Correct middleware = profiling info output [OK]
Quick Trick: ProfilerMiddleware prints profile info to console during requests [OK]
Common Mistakes:
MISTAKES
  • Expecting profiling data in HTTP response
  • Thinking app crashes with middleware
  • Assuming profiling is off without errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes