Performance: How Flask processes HTTP requests
MEDIUM IMPACT
This concept affects the server response time and how quickly the browser receives the page content.
from flask import Flask import threading app = Flask(__name__) @app.route('/') def index(): def background_task(): # Simulate slow processing without blocking import time time.sleep(5) threading.Thread(target=background_task).start() return 'Hello World!' if __name__ == '__main__': app.run()
from flask import Flask app = Flask(__name__) @app.route('/') def index(): import time time.sleep(5) # Simulate slow processing return 'Hello World!' if __name__ == '__main__': app.run()
| Pattern | Server Processing | Response Delay | User Impact | Verdict |
|---|---|---|---|---|
| Blocking long tasks in request handler | High CPU wait | High delay (seconds) | Slow page load, poor LCP | [X] Bad |
| Background task for slow operations | Low CPU wait in handler | Minimal delay | Fast page load, good LCP | [OK] Good |