Reputation: 25
I downloaded a python script but I have a problem with the script, the problem is that it stops working but when I stop the program and rerun it it has a good feature to resume the process which was terminated last time and it continues the process for some time but again stops working. So,
I want to create an another script which terminates the real python script and reruns it every 5 mins...
but when the real python script starts it asks if we want to continue the old terminated process and we have to enter 'y'...
Can anyone help me with this and you can use any language to create the rerunning script. ThankYou
Upvotes: 1
Views: 140
Reputation: 25
ThankYou everybody for their contribution here, after reading all your answers I finally resolved the issue. Here's what I did:
Once again Thank You everybody!
Upvotes: 0
Reputation: 545
You might need is an error handler, instead fixing the error with another python scripting.
The specific solutions depend on the code, but in general it will need python_try_except.
What I suggest is that you put the code with the "error" inside the "try" part within a loop that looks for the correct answer, and the "except" part will store the errors, then you could re-run that snippet of code for the "mistakes".
Something like this:
while len(errors)>0:
try:
Your_Code_Here
except:
storage the error's index
Edit
If the code is too complex to edit, use this nice explanation How can I make one Python file run another? it show three ways to run one python file inside other. Or Run a Python script from another Python script, passing in arguments [duplicate]
Using the try-except, you could put execfile('file.py')
where is "Your_Code_Here
"
try:
execfile('file.py')
except:
# Re-Run flag | Repeat code
pass
Upvotes: 0
Reputation: 354
I agree that you might add try-catch clauses, but replying to your question, you can use subprocess
library
import subprocess
subprocess.call(["python", "your_script.py"])
Upvotes: 1