Home > OS >  Stop python script every 60 seconds and restart
Stop python script every 60 seconds and restart

Time:11-13

This script loops and even if it crashes it restarts.

Now I want it to restart the script even if it has NOT CRASHED yet.

while True:
    try:
        do_main_logic()
    except:
        pass

I have the loop that restart on crash, but I want it to restart on 60 seconds.

CodePudding user response:

It is pretty hard to understand what you are asking for but i can still show how if works:

while True:
try:
    #Try to do something
except:
    #if it failed
else:
    #if it succeded

CodePudding user response:

You can do this :

from time import sleep
    while True:
    try:
        do_main_logic()
    except:
        sleep(60)
        pass
  • Related