Under Construction
This site is currently under construction. This page is generated by AI and has not undergone thorough review by a human. There may be hallucination!
In fact, for now only /, /reactive, and the llms.txt are carefully crafted by myself.
Flask — using HMR in development¶
Use HMR to reload Python code in-place while developing Flask apps. HMR reruns changed modules and their dependents instead of restarting the whole process, shortening the edit-test loop and preserving in-memory objects when possible.
Install¶
Run¶
What to Observe¶
Once the server is running, you can access the application at http://localhost:5000.
- Visit different endpoints and modify the response logic in your modules.
- Try modifying route handlers and refresh the browser to see changes applied instantly.
- Everything should work as expected, with a much smoother development experience than
flask run --reload.
Important notes¶
- Disable Flask's builtin debug mode reloader. Do not run both HMR and Flask's reloader — run
hmrdirectly. - HMR preserves state only when modules are not re-executed. When a module is changed, it and its dependents are re-executed.
- Native extensions, C-level globals, or code that relies on process-level initialization may not be safe to hot-reload.
Best practices¶
- Move heavy initialization (DB pools, ML models) to modules you edit rarely.
- Make route registration idempotent to avoid double-registering on reload.
- Prefer small, pure route handlers and minimize module-level state.
Example sketch¶
# app.py
from flask import Flask, jsonify
from reactivity import signal
counter = signal(0) # counter can be a reactivity signal
app = Flask(__name__)
@app.get("/count")
def get_count():
return jsonify({"count": counter.get()})
If reloads behave oddly, reproduce in a minimal example and check for double registration or global mutable state. For protocol or C-level breaks, prefer a full restart.
See examples/flask/ for a concrete example.