Skip to content

Instantly share code, notes, and snippets.

@pinguet62
Created July 11, 2019 08:01
Show Gist options
  • Save pinguet62/be61d8e554c8514d2e8b474a995fd7f6 to your computer and use it in GitHub Desktop.
Save pinguet62/be61d8e554c8514d2e8b474a995fd7f6 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import argparse
import os
import signal
import subprocess
import urllib2
parser = argparse.ArgumentParser()
parser.add_argument('--start', required=True)
parser.add_argument('--wait', required=True)
parser.add_argument('--test', required=True)
args = parser.parse_args()
start = args.start
wait = args.wait
test = args.test
# Start
startProcess = subprocess.Popen(start, shell=True)
signal.signal(signal.SIGINT, lambda signum, frame: os.kill(startProcess.pid, signum))
signal.signal(signal.SIGTERM, lambda signum, frame: os.kill(startProcess.pid, signum))
# Wait
while True:
try:
urllib2.urlopen(wait)
break
except:
pass
try:
# Test
subprocess.check_call(test, shell=True)
finally:
# Stop
os.kill(startProcess.pid, signal.SIGTERM)
startProcess.kill()
startProcess.communicate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment