Skip to content

Instantly share code, notes, and snippets.

@hoseinit
Created June 16, 2017 19:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoseinit/a694d784a5c38ea1b0e832a8d4947cd9 to your computer and use it in GitHub Desktop.
Save hoseinit/a694d784a5c38ea1b0e832a8d4947cd9 to your computer and use it in GitHub Desktop.
Rerun python script
import subprocess
import time
while True:
print("Launching process..")
p = subprocess.Popen("python3 script.py", shell=True)
p.wait()
print("Process crashed. Restarting in 2 seconds..")
time.sleep(2)
@hoseinit
Copy link
Author

This will run "script.py" in an infinite loop, if it crashes it waits 2 seconds and restarts it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment