[HN Gopher] Jurigged - Hot code reloading for Python
___________________________________________________________________
Jurigged - Hot code reloading for Python
Author : breuleux
Score : 85 points
Date : 2021-04-09 17:14 UTC (5 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| sachamps wrote:
| what's the vscode theme?
| breuleux wrote:
| Noctis Obscuro
| framecowbird wrote:
| This 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.
| musingsole wrote:
| 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.
| ohples wrote:
| Hot code reloading (ala Erlang) is often used in embedded
| devices for control code where restarting is very expensive.
| Mostly telco and networking devices.
| kikos wrote:
| We use something similar in some of the web crawlers in my
| company, we dynamically load the module that selects the data
| from a web page so that if something (website and/or
| requirement) changes we can just swap the module without
| downtime.
| gloryless wrote:
| Is it pronounced "jew rigged?" I'd go with a different name,
| cause that's like the go-to neo nazi conspiracy theory, that jews
| rig everything.
| cstuder wrote:
| No, it's not.
|
| https://en.wikipedia.org/wiki/Jury_rigging
| coldtea wrote:
| Jury rigging is totally different, and the connection to "jews
| rig everything" is a total stretch (not to mention the
| tradition phrasing of the conspiracy is that jews RUN
| everything, not that they rig it).
| edem wrote:
| Wait what? I thought Python was an interpreted language. Did I
| miss something?
| breuleux wrote:
| Python doesn't re-read a function's source code from the
| filesystem every time it calls it, and that would be a bad idea
| in general since you'd inadvertently crash your running
| programs during development.
|
| 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.
| coldtea wrote:
| So? Doesn't change the fact that once you've intepreted a
| function in some file, you've interpreted it and now it's in
| memory, and you're going to use the same as long as your
| program runs (even if you try to reload the module).
|
| (I mean, this is the default case without using something like
| this project, or other tricks).
| nonameiguess wrote:
| 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...
| dfilppi wrote:
| Interesting. I've done it with no issues on both 27 and 36.
| Just edit the code directly in site-packages.
| rosstex wrote:
| Make sure to turn off auto-save on your editor :)
| aidos wrote:
| If 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']
| breuleux wrote:
| You can also run `jurigged -vm IPython`, for what it's worth
| (or put `import jurigged; jurigged.watch()` in the config).
| There are a few edge cases where jurigged will work and not
| IPython's autoreload, and vice versa. Notably, jurigged updates
| decorated functions a bit more aggressively and only runs the
| code diff so it may keep some state that IPython won't.
| emj wrote:
| Looks 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
| julvo wrote:
| Hey author of reloading here - cool to see this mentioned.
| Would love to know how reloading could be more usable for you.
|
| 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.
___________________________________________________________________
(page generated 2021-04-09 23:01 UTC)