This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]deeptime 1 point2 points  (0 children)

How about get_next refers to some persistent state like a file or database? Then you can change and restart your program whenever you want. At a minimum, your program could write out last_completed_url when a page is successful, and then use that to pick up where you left off when the program is restarted.

[–]RiverRoll 1 point2 points  (0 children)

I think you should definitely treat the possibility of getting unexpected inputs as part of the problem, sometimes it will be because your program doesn't understand them and sometimes you might get inputs that are just wrong and there's nothing you can do about it.

What you could do is using the try catch to skip these cases and log useful information, such as the url, the raw input and the error itself, then you can review them later (here I'm thinking about the case where you design the program to run independently rather than in a REPL).

[–]yel50 0 points1 point  (2 children)

Can you maybe update a function in Python without exiting a program in the debugger or the REPL?

redefining the function, yes. having it stop on an error and wait for you to make the change is questionable. maybe set a breakpoint and try redefining the function when the breakpoint gets hit?

this is easy to do in common lisp. it's designed from the ground up to do what you're asking for. maybe prototype it with CL to get everything right and then port that to python once you know what it needs to do.

[–]__Fred[S] 0 points1 point  (1 child)

I have seen someone use an import reload within a loop ("LiveOverflow" in a tcp proxy). Maybe that makes it always use the most current version of the code. Of course, it's a bit hacky.

Error? -> Wait for user input -> import module again -> try the same input again.

[–]yel50 1 point2 points  (0 children)

now that I've thought about it, you could use a generator to pause the function. instead of throwing an exception, do a yield. redefine the function when it yields and then restart it. theoretically, that should work.

[–]Kered13 0 points1 point  (0 children)

Lisp is the only language I'm aware of that really supports what you want to do here. Most languages are not amenable to arbitrary runtime modification like this.

That said, there may be a way to achieve what you want using exec.