简体   繁体   中英

Stop python script every 60 seconds and restart

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.

You can do this:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM