1

I'm using python scripts to execute simple but long measurements. I as wondering if (and how) it's possible to edit a running script.

An example: Let's assume I made an error in the last lines of a running script.These lines have not yet been executed. Now I'd like to fix it without restarting the script. What should I do?

Edit: One Idea I had was loading each line of the script in a list. Then pop the first one. Feed it to an interpreter instance. Wait for it to complete and pop the next one. This way I could modify the list.

I guess I can't be the first one thinking about it. Someone must have implemented something like this before and I don't wan't to reinvent the weel. I one of you knows about a project please let me know.

P3trus
  • 6,747
  • 8
  • 40
  • 54
  • That's what I wan't to avoid. – P3trus Mar 25 '13 at 06:55
  • Related: http://stackoverflow.com/questions/31878055/is-there-any-way-to-retrieve-a-local-variable-from-a-running-function I'd suggest reading through the comments there and the posted answer. Ultimately none of it helped me as I opted for the restart option, but it might help you – Frikster Oct 09 '15 at 04:51

1 Answers1

0

I am afraid there's no easy way to arbitrarily modify a running Python script.

One approach is to test the script on a small amount of data first. This way you'll reduce the likelihood of discovering bugs when running on the actual, large, dataset.

Another possibility is to make the script periodically save its state to disk, so that it can be restarted from where it left off, rather than from the beginning.

NPE
  • 486,780
  • 108
  • 951
  • 1,012