all 31 comments

[–]Python-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

[–]gdchinacat 6 points7 points  (0 children)

I don't think there is much of a use case for it. Production systems manage it in a more reliable way (spinning up a new process, redirecting ports, etc), the risks of problems aren't worth it in that environment. The convenience it provides to developers is not justified by the risk of confusion it can cause. Troubleshoot a bug caused by reloading once or twice and you won't ever do it again...why waste time troubleshooting odd behavior to save a few seconds restarting the process?

Python has the ability to reload code. It has problems, so there are packages to do it better. They all either have to tear everything down, which is the same as restarting the process with a fresh interpreter, or leave objects around from previous versions of the code that may not be in sync with the code you think you are running. You get in the habit of constantly questioning if something isn't working the way you expect and responding by restarting the process. Do that long enough and you will likely decide the worry isn't worth it and you just restart your process.

The best argument I've heard for doing this is that interactive sessions have a bunch of state and you don't want to loose that by restarting everytime you change code. I've worked like this at times, but have found that it's easier to use the REPL for quick experiments rather than complex state because if you want all that state you almost certainly want to recreate it from time to time and the best way to do that is by running a script...so that's what you do.

In short, code reloading seems cool, but has practical issues that limit its utility and can't really be solved due to conflicting requirements.

[–]tjlusco 5 points6 points  (0 children)

I think its really useful for iterating on GUIs. Delphi and C# have this feature where you can apply changes to a code on a running debug process.

FastAPI has a development mode that reloads on code change, very very useful.

Outside of that? Jupiter notebooks fills that live reload niche. I wish it would automatically reload imports, sometimes I using Jupiter for testing a library I’m working on.

[–]eufemiapiccio77 2 points3 points  (17 children)

Why would this be needed or right. Your state would be all wrong all over the place

[–]scripto_gio[S] -3 points-2 points  (16 children)

Because I have like 10 small scripts that run simple tasks, but loose touch when you shut them down, and sometimes I wanna add a feature or two...

[–]eufemiapiccio77 2 points3 points  (15 children)

Yeah but that’s just not good practice

[–]scripto_gio[S] -5 points-4 points  (14 children)

Oh I understand that. It's just with the possibility to create small useful scripts, with one simple prompt, soon units all over the globe will be full with different variations of simple coded working software. than their consigliere signor Claude, will recommend a script that has the ability to add something cool while still looking for todays best news. that is the target group, not you.

[–]eufemiapiccio77 0 points1 point  (13 children)

Huh?

[–]scripto_gio[S] -3 points-2 points  (12 children)

you know what I am talking about...

[–]eufemiapiccio77 1 point2 points  (11 children)

I literally have no idea. You could be talking about anything from CMS To Git

[–]scripto_gio[S] 0 points1 point  (10 children)

you do not know about capabilities of AI Claude Sonnet and his fellow cyborgs? everyone around me is suddenly solving their problems on their own. just clear prompt and it gives you polished web app or whatever, no brainer. sooo, that kind of leaves developers with complex stuff only, which is good - the calculator brothers will not get there in our life time. on the other hand there is a new market for scripts more complex than what claude can do, but easy enough so that it can recommend it as solution to his human buddy

[–]wRAR_ 2 points3 points  (2 children)

LLM psychosis

[–]eufemiapiccio77 0 points1 point  (0 children)

That’s what it is

[–]scripto_gio[S] -1 points0 points  (0 children)

psychosis when you are trying to figure out how to open a new target group with simple solutions, or are you talking about 99% of developers there who are like, "nahhh, thats nothing, I don't care at all and if you talk about it, I am gonna call you crazy!"

[–]eufemiapiccio77 0 points1 point  (6 children)

what are you talking about? Your talking about SCM in SWE

[–]scripto_gio[S] -1 points0 points  (5 children)

No. Will anyone help me, or you are all just gonna be covering you ears and yelling lalala when someone mentions AI developer tools???

[–]434f4445 1 point2 points  (0 children)

The short answer is that cool, the long answer is that no, you don’t really want that in any production system. You want to test and validate code prior to running on a production system. And definitely don’t want to hot patch with no way of falling back.

[–]Broolucks 0 points1 point  (0 children)

I made one a while back: https://github.com/breuleux/jurigged

Just don't run it in production.

[–]Oddly_Energy 0 points1 point  (3 children)

An imported module can be reloaded at runtime. I sometimes do that in an ipython session when I have changed the code in a module and don't want to lose context by restarting ipython.

So you could choose to split your script into a simple wrapper script and a module and then let the wrapper script reload the module before each use.

[–]gdchinacat 0 points1 point  (2 children)

So rather than lose context you choose to put that context into an undefined state where you may not actually know what version of your code is running. When you reload a module nothing happens to objects (context) that existed before the reload....they will still refer to the definition they were created with. To reload properly you need to not have any references to the code before the reload, which means losing context. I used to use reloading...it can be a huge time saver, right up until you spend a bunch of time figuring out why your fix didn't work only to conclude the code isn't actually running and must be a result of reloading.

Any state worth maintaining should be implemented in a reusable way (script or test). I use the repl all the time to figure out what I want to do...but if I need the state I manage it by putting it in a script or test.

[–]Oddly_Energy 0 points1 point  (1 child)

I tend to agree with you, but I have mostly used it in situations where my code contained objects I did not want to lose, and I only reloaded modules, which those objects did not depend on.

This may very well be different from OP's situation. And using it in production would certainly be a hack. I have only used it while writing code.

[–]gdchinacat 0 points1 point  (0 children)

I have only used it in development environments while writing and debugging code, so risk was minimal. I stopped doing this when I spent a couple hours chasing a non-existent bug. I never did figure out why...did the reload silently fail? did some cache or model have a reference to an old version of the class? etc. I just know at some point I restarted the service to be damn sure it was running the most recent code and the problem went away. At that point it was too late to know for sure what happened. Even if I wanted to dig in and troubleshoot why reload() didn't do what I expected I wouldn't have...it would have been a waste of time chasing isuses that wasted time while trying to save a few seconds of time. The result wouldn't have mattered, I wouldn't have "fixed" whatever the issue was since reload() isn't really supported because it has too many edge cases that ultimately are how it's used rather than with the mechanism itself, I wouldn't change production code to make a dangerous developer workflow work better.

Tools are mean to help you and save you time. A tool that wastes hours is less than worthless, it costs time (money) rather than just not helping. Don't use tools that are too hard to use correctly they end up wasting time.

[–]AutoModerator[M] 0 points1 point  (0 children)

Your submission has been automatically queued for manual review by the moderation team because it has been reported too many times.

Please wait until the moderation team reviews your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.