Hot-reloading not working when a module is imported with `from foo import bar`
See original GitHub issueSummary
@Icerman observes hat hot reloading works as expected when modules are imported like:
import foo.bar
or
import foo.bar as bar
but when importing the same module using:
from foo import bar
then its changes are ignored.
Steps to reproduce
Steps to reproduce are described below.
Debug info
@MarcSkovMadsen gave his system information below.
Additional information
This is the first of two bugs based on this awesome-streamlit
issue. The second bug is this.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Python: reload component Y imported with 'from X import Y'?
Answer. From my tests, the marked answer, which suggests a simple reload(X) , does not work. From what I can tell the correct...
Read more >Programming FAQ — Python 3.11.1 documentation
Running Python on a top level script is not considered an import and no .pyc will be created. For example, if you have...
Read more >Modules - Beginner JavaScript - Wes Bos
You can import it from that file. Importing and Exporting Modules. There are two types of module imports: Named Imports; Default Imports.
Read more >react-hot-loader - npm
Start using react-hot-loader in your project by running `npm i ... Use hot only for module exports , not for module imports ....
Read more >Features | Vite
Native ES imports do not support bare module imports like the following: ... warn you against the features that do not work with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello I have run in the same issue recently. It seems that auto-reload works as expected when modules are imported like:
or
but when I import the same module using:
then its changes are ignored.
Steps to reproduce:
main_ok.py:
main_ok2.py:
main_ko.py:
foo/bar.py:
streamlit run main_ok.py
orstreamlit run main_ok.py2
but ignored when run the app asstreamlit run main_ko.py
My system is Ubuntu 18.04 running inside WSL at Windows 10, Python 3.6.8.
Notes, as I’m investigating:
from foo import bar
modulesLocalSourcesWatcher.update_watched_modules
,sys.modules
includes these modules as expectedsys.modules
seems to… lose them?sys.modules
pruning fromLocalSourcesWatcher.on_file_changed
(removing any watched file that changes fromsys.modules
), but I’m not sure why. – Per @tvst, this is to force python to reload that module.on_file_changed
, changing the module causes a re-run as expected. But: it’s as if the module itself is not being reloaded; no changes are reflected.reload()
watched modules before re-running?https://stackoverflow.com/questions/7271082/how-to-reload-a-modules-function-in-python
sys.modules
all over the place. Do we need to be more careful with this, across multiple threads? (Or maybe we don’t support hot-reloading if > 1 user is connected?)