Wait what? I thought Python was an interpreted language. Did I miss something?
Imported modules are compiled to bytecode and frozen on import, so changing the code in-place won't change what actually get run when the code is called unless you clear the bytecode cache and re-import. importlib provide a reload method for this purpose: https://docs.python.org/3.8/library/importlib.html#importlib...
Jurigged – Hot code reloading for Python
11–20 of 33 posts
Re: Jurigged – Hot code reloading for Python
#12Re: Jurigged – Hot code reloading for Python
#13Wait what? I thought Python was an interpreted language. Did I miss something?
This watches for changes on the filesystem and injects them into the running program as well as it can, basically keeping the current program state but with new behaviour.
This is kind of a footgun and there are many changes you can make that will crash or ruin the process, but if you're aware of the limitations it can be pretty useful.
Re: Jurigged – Hot code reloading for Python
#14Re: Jurigged – Hot code reloading for Python
#15To enable it add the following to your ipython_config.py:
c = get_config()
c.InteractiveShellApp.exec_lines = ['%autoreload 2']
c.InteractiveShellApp.extensions = ['autoreload']Re: Jurigged – Hot code reloading for Python
#16If you use iPython you can enable auto reloading for all your sessions. It works really well - I've been using it for years. You need to know the limitations, but on the whole it give huge performance gains when I'm coding. To enable it add the following to your ipython_config.py: c = get_config() c.InteractiveShellApp.exec_lines = ['%autoreload 2'] c.InteractiveShellApp.extensions = ['autoreload']
Re: Jurigged – Hot code reloading for Python
#17This looks impressive, and equally a recipe for utter confusion. I've always thought that it's a brilliant feature of Python that you can edit code while it's running and not affect the process; unlike, say, bash scripts.
In a proper managed environment (whatever that may mean...), this could be useful as a means for continuous integration. Maybe not worth all the hassle, but maybe there's a usecase where this would be a beloved silver bullet.
Re: Jurigged – Hot code reloading for Python
#18Looks more usable than the reloading library which does a similar thing, going to be interesting to use them together. I found Reloading when it was discussed in 2019: https://news.ycombinator.com/item?id=21268324
Since the post on HN in 2019, reloading can also be used as a decorator to load functions from source before execution. For some use cases that may work better than the reloading loop.
Re: Jurigged – Hot code reloading for Python
#19Re: Jurigged – Hot code reloading for Python
#20what’s the vscode theme?