Skip to content

Instantly share code, notes, and snippets.

@gronnbeck
Created August 30, 2021 09:41
Show Gist options
  • Save gronnbeck/f0da26ded18554304bbf65b5f6667055 to your computer and use it in GitHub Desktop.
Save gronnbeck/f0da26ded18554304bbf65b5f6667055 to your computer and use it in GitHub Desktop.
Restart a program after x seconds
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