-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Description
Hot Module Replacement has been existed in JavaScript ecosystem for a long time, but Python web applications are still using full reloads by default.
To solve this situation, I implemented the hmr package, which does the fine-grained dependency tracking, on-demand reloading jobs. Here is a demo of what the results look like:
flask.mov
Obviously the a.py runs everytime in flask run --reload but reloads only when needed in hmr app.py. But everything else works fine (at least for this small demo)
You may say that user should use lazy imports and cache expensive calculations themselves, but in fact not every function can be cached, and lazy imports may lead to ugly code style. This can be solved with on-demand hot reloading without overhead. So I believe this is the future.
Although this is just a minimal demo, but I value hmr's potential in the Python ecosystem, and believe that with our efforts this is a reachable goal.
Tip
You can try the example above here with hmr app.py
About hmr, you can refer to its README for details.