Imagine a Flask web app that takes 5 seconds to respond to each user request. What is the most likely impact on users?
Think about how you feel when a website takes too long to load.
Fast response times keep users happy and engaged. Slow responses cause frustration and can lead to users leaving.
Consider a Flask route that waits for a slow database query before responding. What is the effect on the app's performance?
from flask import Flask app = Flask(__name__) @app.route('/') def index(): # Simulate slow DB query import time time.sleep(5) return 'Done'
Think about how Flask handles requests in its default setup.
Flask by default handles requests one at a time per worker. A blocking call like sleep pauses the worker, delaying other requests.
Given a Flask route that caches expensive results, what is the expected effect on response times for repeated requests?
from flask import Flask app = Flask(__name__) cache = {} @app.route('/data') def data(): if 'result' in cache: return cache['result'] # Simulate expensive calculation import time time.sleep(3) cache['result'] = 'Expensive Data' return cache['result']
Think about what happens after the first slow calculation finishes.
The first request takes time to compute and store the result. Later requests return the cached data immediately, speeding up responses.
Which option contains a syntax error that would prevent Flask app from starting?
from flask import Flask app = Flask(__name__) @app.route('/') def home(): return 'Hello World' if __name__ == '__main__': app.run(debug=True)
Check function definitions for correct syntax.
Option B is missing a colon after the function name, causing a syntax error and preventing app startup.
Analyze the code below. Why does the app hang when multiple users access it simultaneously?
from flask import Flask app = Flask(__name__) @app.route('/') def index(): while True: pass return 'Done'
Consider what an infinite loop does to a single-threaded server.
The infinite loop never ends, so the worker is stuck and cannot process other requests, causing the app to hang.