Here is my working code. It works great in the lab, but I still need to test it on a live system. I also need to add the email notifications to it, but I purposely left them out for now; I will also adjust the sleep time to a more appropriate amount. Anyone see any issues with it or ways to make it better?
#!/usr/bin/env python import subprocess from subprocess import PIPE import time import psutil import sys count = 0 restart = 0 def kill_proc(process1, process2): i = psutil.Popen(["ps", "cax"], stdout=PIPE) out, err = i.communicate() for proc in psutil.process_iter(): if proc.name == process1 and process2: proc.kill() while True: while count < 15: count += 1 kill_proc("bmdplay", "avconv") print "Starting the script", count time.sleep(2) p = subprocess.Popen("/Downloads/bmdtools/test_loop.sh", shell=True, stderr=PIPE) for line in p.stderr: print line if "Segmentation" in line: kill_proc("bmdplay", "avconv") while restart < 3: restart += 1 time.sleep(2) p = subprocess.Popen("/Downloads/bmdtools/test_loop.sh", shell=True, stderr=PIPE) for line in p.stderr: print line if restart == 3: # send email saying so sys.exit() if "storing 0x" in line: kill_proc("bmdplay", "avconv") while restart < 3: restart += 1 sleep.time(2) p = subprocess.Popen("/Downloads/bmdtools/test_loop.sh", shell=True, stderr=PIPE) for line in p.stderr: print line if restart == 3: # send email saying so sys.exit() if count == 10: print "Going to sleep, will try again in..." #send email saying so time.sleep(2) if count == 15: # send email saying so print "Gave up" break break
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor