3 ms·
For comparison, here’s Werkzeug’s reloader implementation: https://github.com/pallets/werkzeug/blob/master/src/werkzeug/_reloader.py https://github.com/pallets/
by oefrha 6y ago
For comparison, here’s Werkzeug’s reloader implementation: https://github.com/pallets/werkzeug/blob/master/src/werkzeug/_reloader.py https://github.com/pallets/werkzeug/blob/master/src/werkzeug... (when you flask run or call app.run with reloader turned on, it’s handled by this module.)
- sillysaurusx 6y agoThanks! That `_iter_module_files()` function is handy. Unfortunately, it looks like it simply restarts Python each time the code changes: https://github.com/pallets/werkzeug/blob/75215972967c1c00c15b8b5c3c661c2278423360/src/werkzeug/_reloader.py#L156 https://github.com/pallets/werkzeug/blob/75215972967c1c00c15... which isn't quite the same thing as reloading it.
- the_mitsuhiko 6y agoIt used to do hot reloading back in the days but unfortunately that doesn’t really work in Python because of all the import side effects. It’s better to restart everything. Werkzeug keeps the socket open so you don’t observe the reload from the outside.
- oefrha 6y agoActual reloading is just hairy and you can end up with semi-broken instances among other things. Restarting the interpreter is just cleaner, and it's totally acceptable for a dev server. (Okay looks like Armin himself replied too, obviously take his words above mine.) I pointed to IPython's autoreload in another reply which is more powerful than importlib.reload.
- raziel2p 6y agoWhy is that unfortunate?