简体   繁体   English

每 60 秒停止 python 脚本并重新启动

[英]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.我有在崩溃时重新启动的循环,但我希望它在 60 秒后重新启动。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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