Skip to content

Commit

Permalink
validate: launcher: Don't wait for processes longer than necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramiro Polla authored and tsaunier committed Feb 5, 2015
1 parent db69518 commit bdedd7a
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions validate/launcher/baseclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import signal
import urlparse
import subprocess
import threading
import reporters
import ConfigParser
import loggable
Expand Down Expand Up @@ -59,6 +60,8 @@ def __init__(self, application_name, classname, options,
self.command = ""
self.reporter = reporter
self.process = None
self.proc_env = None
self.thread = None
self.duration = duration

self.clean()
Expand Down Expand Up @@ -167,14 +170,13 @@ def wait_process(self):
last_change_ts = time.time()
start_ts = time.time()
while True:
# Check process every second for timeout
self.thread.join(1.0)

self.process.poll()
if self.process.returncode is not None:
break

# Dirty way to avoid eating to much CPU...
# good enough for us anyway.
time.sleep(1)

val = self.get_current_value()

self.debug("Got value: %s" % val)
Expand Down Expand Up @@ -231,11 +233,19 @@ def _kill_subprocess(self):
% DEFAULT_TIMEOUT)
res = self.process.poll()

def thread_wrapper(self):
self.process = subprocess.Popen("exec " + self.command,
stderr=self.reporter.out,
stdout=self.reporter.out,
shell=True,
env=self.proc_env)
self.process.wait()

def run(self):
self.command = "%s " % (self.application)
self._starting_time = time.time()
self.build_arguments()
proc_env = self.get_subproc_env()
self.proc_env = self.get_subproc_env()

message = "Launching: %s%s\n" \
" Command: '%s %s'\n" % (Colors.ENDC, self.classname,
Expand All @@ -255,18 +265,17 @@ def run(self):

printc(message, Colors.OKBLUE)

self.thread = threading.Thread(target=self.thread_wrapper)
self.thread.start()

try:
self.process = subprocess.Popen("exec " + self.command,
stderr=self.reporter.out,
stdout=self.reporter.out,
shell=True,
env=proc_env)
self.wait_process()
except KeyboardInterrupt:
self._kill_subprocess()
raise

self._kill_subprocess()
self.thread.join()
self.time_taken = time.time() - self._starting_time

printc("Result: %s%s\n" % (self.result,
Expand Down

1 comment on commit bdedd7a

@thiblahute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Please sign in to comment.