Performance: Command pattern with Flask CLI
MEDIUM IMPACT
This affects the startup time and responsiveness of the Flask CLI commands, impacting how quickly commands execute and return results.
import click from flask import Flask app = Flask(__name__) @app.cli.command() @click.pass_context def cleanup(ctx): import time # Import inside command to delay cost time.sleep(1) # Simulate work only when command runs print('Cleanup done')
import click from flask import Flask # Heavy imports and operations at global scope import time time.sleep(5) # Simulate slow startup app = Flask(__name__) @app.cli.command() def cleanup(): print('Cleanup done')
| Pattern | Import Timing | Startup Delay | Execution Delay | Verdict |
|---|---|---|---|---|
| Heavy global imports | At CLI start | High (blocks startup) | Low | [X] Bad |
| Lazy imports inside command | At command run | Low (fast startup) | Moderate | [OK] Good |