1
私は24/7を実行する必要があるpythonプログラムを持っています。それは30秒間隔で約10%の時間眠っている。プログラムを停止して安全に再開させる方法がありますので、スリープ中に再起動するだけですか?睡眠中のpythonプログラムを安全に再起動しますか?
def main():
restart_file = config.get('some_section', 'restart_file')
while True:
checkReply = Reply()
checkReply.time_to_reply()
checkReply.search_db()
time.sleep(10)
if os.path.exists(restart_file):
os.unlink(restart_file)
if 0 == os.fork():
os.execl(shlex.split('command to run the updated program'))
sys.exit('restarting')
追加クレジットの場合:
# =============================================================================
# MAIN
# =============================================================================
def main():
while True:
checkReply = Reply()
checkReply.time_to_reply()
checkReply.search_db()
time.sleep(10)
# =============================================================================
# RUNNER
# =============================================================================
print "start"
if __name__ == '__main__':
main()
ええ、私はそれを行う方法を示すことができますが、コードを投稿する必要があります。少なくともプログラムの制御フローを示す例。 – Will
ありがとう、うまくいけばあまりにも醜い櫛を介してではない。 https://github.com/SIlver--/remindmebot-reddit –