modify a running python program
Asked Answered
F

2

10

I launched a python program with many nested loops, and the program will take days. I just realized that one of the loops values is wrong and makes a infinite loop.

I don't want to restart the program from zero, is there a way to interrupt the current program and modify the loop range so it will work properly and also if it was trapped with the infinite loop to break it?

Many thanks for your help.

Feckless answered 25/6, 2012 at 9:25 Comment(1)
See here for some hints.Graff
V
1

If the program saves its state or its results from time to time, you could add a logic which skips the steps which have already executed.

Otherwise, I don't see a way to change this.

Vary answered 25/6, 2012 at 9:32 Comment(0)
S
0

I guess pretty old article but just came across now. In case you still want to try you could do the following:

Make your script run under pdb as: python -m pdb

This will run it under pdb. After entering pdb just enter command 'c' (continue). This will begin your program.

When you encounter a infinite loop just do a ctrl+c this will stop the program within the debugger. Now you could run any python statements you want. Possibly you could also define a new script import it and run functions from that script or exit.

I know it is not a good idea to always run under debugger, but at least the above would solve what you intended for.

Skyward answered 20/3, 2013 at 21:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.