Last active
December 24, 2015 00:58
-
-
Save sciurus/6720021 to your computer and use it in GitHub Desktop.
Process monitor
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
#!/usr/bin/env python | |
import os, re, signal, subprocess | |
def monitor(): | |
print "Starting procedure" | |
p = subprocess.Popen('./problematic_procedure.py', | |
stdout=subprocess.PIPE | |
) | |
while p.poll() is None: | |
line = p.stdout.readline() | |
print "Procedure output was %s" % line | |
if re.match('bad', line): | |
os.kill(p.pid, signal.SIGTERM) | |
print "Procedure failed so I killed it" | |
monitor() | |
monitor() | |
print 'Procedure exited' |
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
#!/usr/bin/env python | |
import random, sys, time | |
while True: | |
r = random.randint(1,6) | |
if r == 1: | |
sys.exit() | |
elif r == 2 or r == 3: | |
print "bad" | |
sys.stdout.flush() | |
else: | |
print "good" | |
sys.stdout.flush() | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment