8 ms·
Reloadium – Advanced hot reloading for Python
- aidenn0 4y agoI assume this also makes it possible to reload a function/file when not in the middle of a breakpoint? That is something that is super-useful in lisp (reloading under both situations that is), but AFAICT impossible in vanilla python due to the way imports work.
- kwazar90 4y agoYes hot reloading also works when not suspended and without using debugger. Although you won't be able to reload the current function (currently executing on the call stack) until you suspend it with a breakpoint.
- hprotagonist 4y agoIn general this shouldn't be possible, due to how the import mechanisms of python operate. I wonder how easy it is to break this / stale state / the usual and cause truly incomprehensible state bugs?
- kwazar90 4y agoYes it is very difficult, it took me one year and thousands of unit, integration, e2e tests for it to become usable. It is quite stable now although in some situations a full reload still might be needed.
- whalesalad 4y agoKudos for persisting through the muck and shipping.
- uniqueuid 4y agoLive reloading is difficult, but it has some use cases. There was some interesting discussion the last (?) time the topic was posted [1] and some links to similar projects. In general, the limitations seem to prevent me from using techniques such as this as a default. [1] https://news.ycombinator.com/item?id=26035623 https://news.ycombinator.com/item?id=26035623
- kwazar90 4y agoWhat limitations exactly do you have in mind? Reloadium does not cause issues with redefined objects ("is" operator issues)
- uniqueuid 4y agoOne thing that comes to mind is additional imports. For example, what would happen with Reloadium if an edit introduces a circular dependency? Will it resolve a tree of changes to multiple files?
- kwazar90 4y agoIf you intruduce a circular dependency (or any Python execution error) it will rollback all already applied actions, highlight the issue and wait for you to fix it. Reloadium reloads modules across the whole project so it is possible.
- wrycoder 4y agoOr, if you are developing, just use IDLE.
- toxik 4y agoPlease don’t post low-effort dismissals of people’s projects. Not only is it rude, but also insubstantial. You can just say “IDLE does something similar […]”, and substantiate the claim. FYI, IDLE does not do what this project aims to do.
- wrycoder 4y agoIDLE restarts the entire computation in a subprocess every time you press “run”. It is excellent for beginners and small projects, as no reloading is required when you change the code of an imported module.
- Shish2k 4y agoThat’s great… but that’s not what this module is for
- wrycoder 4y agoI understand, but, except in those few cases that require hot reloading into a running program, it's conceptually much more straightforward and less risky to simply restart the computation. It can cause a beginner considerable (a|be)musement, when a change to an imported module isn't reflected in the output as expected. From the docs: "In many cases extension modules are not designed to be initialized more than once, and may fail in arbitrary ways when reloaded." and "If a module instantiates instances of a class, reloading the module that defines the class does not affect the method definitions of the instances — they continue to use the old class definition. The same is true for derived classes."
- uniqueuid 4y agoThere may be a completely new approach, by the way, in the very interesting unison language [1]. Because its code is content-addressed, reloading should be possible by swapping out function identifiers (which are hashes, not names). Because the AST refers to functions by ID not name or label, one could perform replacements/changes without interfering with any existing code. [1] https://www.unison-lang.org/ https://www.unison-lang.org/
- kwazar90 4y agoInteresting, is it already supported?
- uniqueuid 4y agoAs far as I know not. Unison currently seems focused on the cloud angle (which is also cool and smart). The idea is that you can offload computation to some other server even when it does not have the code, since it will just fetch the necessary function implementations from a global register.
- ewuhic 4y agoWould it perform IO in background if a line states to, say, delete a file?
- kwazar90 4y agoAs in whether it tracks IO file operations, to know to rollback a file deletion?
- ewuhic 4y agoAs to not delete my home folder or issue DROP TABLES as I see it also works with SQLA.
- kwazar90 4y agoAs long your code does not state that nothing will happen. About the SQL - the only thing it does is rolling back transaction if you make an error during reloading to recover the db state.
- kapilvt 4y agoIts not clear if this is functional versus aspirational, its missing any useful code minus dataclass model definitions, which makes it rather to hard evaluate if its either useful or safe. https://github.com/reloadware/reloadium/tree/main/src https://github.com/reloadware/reloadium/tree/main/src
- haolez 4y agoVery cool! Most of your social network icons are broken, though.
- kwazar90 4y agoTrue, the website needs some doing...
- djstein 4y agothis is really awesome! thanks for sharing. I was wondering what would happen if used in Django, and bam, there was the example.
- EgoIncarnate 4y agoThe source code on github seems incomplete. Is this a closed source project?
- siilats 4y agoIt has a pycharm plugin too but need some wheels for M1 if anyone can help with the issue I wrote up, would be great ...
- kwazar90 4y agoGithub actions does not support M1 architecture yet so I could not build wheels for it. Support for self hosted runners is coming soon so I will buy an M1 machine and set up a runner myself.
- tracnar 4y agoI've been using jurigged [0] for hot code reloading which is great. It works by replacing code objects in place at the function level which naturally handles many cases like applying to existing objects, avoiding loading a module multiple times, etc. As others noted the actual source of this one is not there so it's hard to know what it's doing. The published package contains a binary shared library so I suppose it's written as a CPython extension. [0] https://github.com/breuleux/jurigged https://github.com/breuleux/jurigged
- breuleux 4y agoJurigged author here, just tried reloadium out of curiosity. I couldn't run it on my M1 Mac (unsupported, it seems), on Linux I was able to, and it seems to work similarly (identifying what needs to be updated and updating these things specifically). That's nice to see. There is one thing jurigged does that this doesn't, which is updating closures, and I also define a protocol for custom libraries to watch changes so that e.g. a multiple dispatch library can update its internal structures when code changes. There may be things reloadium does better, for example it looks like there is some special casing for Flask/etc.? Not sure how that scales. I didn't try the PyCharm stuff. Glad jurigged works for you. Coincidentally, I was working on an update today, and I am going to present jurigged at PyCon this weekend :)
- kwazar90 4y agoI have tried jurigged and I like how lightweight it is. It does not seem to reload changes that relate to other parts of code though. For a given code: a = 1 b = a + 2 Changing a = 5 will not update b which will still be equal to 3. The same goes to relations between files. Whether it is a flaw or feature it depends on the situation and codebase I guess. Also it seems like it is not possible to reload currently executing functions (re-entering the function is needed).
- chii 4y agoi wonder how you would make the update to `b` work in this case? If you have a white listed set of pure operations (like the `+` operation), then you can check if the hot-reloaded code has any dependencies which could be re-executed (like the b=a+2 case). You wouldn't want to re-execute code that has a side-effect upon hot reloading imho.
- digisign 4y agoOutside of the Django/Flask use case, not sure what this does: "Reloadium will rerun current function when changed. Developers get instant feedback whether the code is working or not." How does it know what parameters to pass? Makes them up at random? Runs the whole file as a script? Does static analysis? Runs test suite?
- kwazar90 4y agoWhen re-running current function it passes the original arguments (it does not roll them back if changed in the function body - that will be added in the future).
- qorrect 4y agoCan't wait to dig into this. I've been wanting this for python for a long time, love the PyCharm integration right out of the gate.
- daenz 4y agoVery cool, and no doubt a difficult to accomplish feat. But it's unclear how useful it is. The author has a comment in this thread that "in some situations a full reload still might be needed", which makes sense, but also severely damages confidence in the tool. It will be very difficult for a user to understand when a full reload is needed, and if they don't have confidence that the correct code is always running, it makes them less likely to use it. If you can make it crystal clear when full reloading is needed, so that users can gain an intuition about that, it would help this tool a lot.
- kwazar90 4y agoIt does print a message when something can't be hot reloaded. For example changing base classes dynamically is impossible to achive in Python so this is not supported and a full reload is needed. You can go a long way without fully reloading though in many cases.
- daenz 4y agocool, thanks for responding and congrats on your accomplishment! i love innovative tools like this.
- tomatowurst 4y agointeresting....how does it play along with type hints? btw, this is one area where I can't really find a comeback in argument against typescript. would be cool if this somehow let me know before running the python code whether I am passing in the wrong type or not. very nice work, i dont really understand whats happening underneath the hood but any productivity boost is welcome.
- kwazar90 4y agoIt does update type hints as well!
- deleted 4y ago[deleted]
- lpasselin 4y agoI've been waiting for a tool like this for a long time!
- User23 4y agoAdvanced hot reloading is paradigm shifting. It’s one of those tools that’s hard to understand the value of when you’ve never had it. So far as I’m aware Lisp and Smalltalk are the only major languages that actually comprehensively support it. It’s great to see it being incorporated in python because, I hope, it will expand the mental concept of what is possible for millions more programmers.
- macintux 4y agoErlang (and by extension, I presume Elixir) support hot reloading. It’s a core feature used extensively in production.
- hardware2win 4y agoC#?
- igouy 4y agoCoincidentally "Ask HN: Practical examples of runtime modified software" https://news.ycombinator.com/item?id=31151452 https://news.ycombinator.com/item?id=31151452
- oofbey 4y agoThis looks quite cool. But the authors could really use some help with marketing. "Advanced hot reloading" sounds like nothing I'd never be interested in at all. Maybe that's standard jargon for this tech? Never heard it before personally, and I code a lot. My advice: come up with a better way to describe it that doesn't require explaining how it's useful, and a lot more people will try it.
- kwazar90 4y agoIt's just me working on this project, and yeah I'm not super strong with marketing or business neither english is my first language. Do you have any suggestions how to describe it better? Is "Edit and continue" more descriptive (I think this is what Microsoft calls it for .net).
- oofbey 4y agoAs somebody who spends a lot of time in Jupyter, I might say this "lets your IDE work like a notebook." That's what it makes me think. Right now I go to Jupyter when I want to figure out what works interactively. This looks like it would let me do a lot of that from an IDE, which is probably where I want the code to go anyway. Maybe "Notebook interactivity in your IDE"? Or for people who don't use jupyter regularly maybe "interactively debug your code as you write it". Something like that would help me understand how cool this is without watching a screencast. It would get me to watch the screencast. Or to put it another way: think about why users would be interested in it, not about how it works or what it does.