Created
August 30, 2021 09:41
-
-
Save gronnbeck/f0da26ded18554304bbf65b5f6667055 to your computer and use it in GitHub Desktop.
Restart a program after x seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import time | |
def start_program(program): | |
proc = subprocess.Popen([program], stdout=subprocess.PIPE) | |
return proc | |
def run(program, time_seconds): | |
while True: | |
proc = start_program(program) | |
time.sleep(time_seconds) | |
print('Restarting program') | |
proc.kill() | |
run('./infinite.sh', 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment