Skip to content

Instantly share code, notes, and snippets.

@h2rd
Last active December 11, 2015 04:49
Show Gist options
  • Select an option

  • Save h2rd/4547979 to your computer and use it in GitHub Desktop.

Select an option

Save h2rd/4547979 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from os import path
import subprocess
import time
import sys
def run(filename):
""" Run Subprocess scripts and control them """
process = subprocess.Popen(['python', filename], shell=False,
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
process.poll()
return process
if __name__ == '__main__':
filename = sys.argv[1]
if not path.exists(filename):
print 'File %s not exists' % (filename)
sys.exit();
process = run(filename)
c = 0
while True:
returncode = process.wait()
if returncode != None:
process = run(filename)
c+=1
print "%s restarted %d times" % (filename, c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment