1

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

3 Answers3

1

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"])
Carlos Rojas
  • 334
  • 5
  • 13
  • ThankYou for the answer but when the python script will run it asks if I want to continue the terminated process so how can it automatically send 'y'? – Muaviz Mushtaq Shah Jan 06 '21 at 07:56
0

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
Alfredo Maussa
  • 515
  • 2
  • 8
  • I appreciate your answer but the python script that I have is not mine and it's not a small script, it's a complex one using proxies and all, I don't think I have much knowledge to change the code to fix errors so that's why I am trying this strange method. If you can help me with that then I would appreciate that. ThankYou! – Muaviz Mushtaq Shah Jan 06 '21 at 07:41
  • check in [How can I make one Python file run another?](https://www.tutorialspoint.com/How-can-I-make-one-Python-file-run-another) it show three ways to run a script inside other – Alfredo Maussa Jan 06 '21 at 07:59
  • the missing issue is to send [keypress "y"] when re-run it. execfile('file.py y') probably don't work since is a parameter and not a keypress signal. Maybe exist another way to solve this, but i only can imagine an external bot with python for send the [y keypressed] signal. – Alfredo Maussa Jan 06 '21 at 08:14
  • Should I delete the answer as it doesn't exactly try to solve the original question? (I am new here) – Alfredo Maussa Jan 06 '21 at 08:24
0

ThankYou everybody for their contribution here, after reading all your answers I finally resolved the issue. Here's what I did:

  1. I first changed the real python script deleted the code which asked if i wanted to continue the terminated process, so now it simply checks if any session exists and if it does exist then it directly resumes the process.
  2. Then I created another Python program which simply reruns the real python file.

Once again Thank You everybody!