(bug) When running a script that makes use of another script...
When running a script a.py that import b.py, and I modify b.py once a.py as already been launched, I have to quit Pythonista for the a.py to reload and take into account modifications made in b.py ...
Is that a bug or some sort of optimisation that avoid recompiling the byte code that I can disable in the settings?
It's an optimization in core Python. When a module is imported for the first time, it is stored in the dictionary
sys.modules. If a module is already listed there, the existing instance is reused and the file is not reloaded from disk. This is especially noticeable in Pythonista because the entire app internally uses a single Python interpreter instance for the interactive console, user scripts, editor actions, etc. On a normal computer you'd run your program in its own Python process, e. g. by typing
python helloworld.pyin the shell. That process exits when the program is finished, and
sys.modulesis discarded. In Pythonista this only happens when the app is removed from the background, either because iOS needs RAM or because you manually quit it.
Ok, so this is kind of a known issue that you have to quit Pythonista for sub modules to be properly reloaded by scripts using it, once edited?
You can use the built-in reload() function to reload a module without having to quit Pythonista. It's likely that this won't be necessary anymore in the next update though.
thx that's a good workaround while working on a sub module