Performance: Teardown hooks
MEDIUM IMPACT
Teardown hooks affect the cleanup phase after a request, impacting server response time and resource release efficiency.
from flask import Flask app = Flask(__name__) @app.teardown_request def teardown(exception): db = get_db() if db: db.close() # Close connection promptly # Avoid heavy or blocking operations here
from flask import Flask import time app = Flask(__name__) @app.teardown_request def teardown(exception): # Closing database connection inefficiently db = get_db() db.close() # Heavy synchronous cleanup time.sleep(2) # Simulate slow cleanup
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Blocking teardown with slow cleanup | 0 | 0 | 0 | [X] Bad |
| Quick resource release in teardown | 0 | 0 | 0 | [OK] Good |