Browse Source

Attempting to kill by group

msmith-techempower 8 years ago
parent
commit
cf7d2baa48
2 changed files with 16 additions and 20 deletions
  1. 13 18
      toolset/benchmark/benchmarker.py
  2. 3 2
      toolset/benchmark/framework_test.py

+ 13 - 18
toolset/benchmark/benchmarker.py

@@ -566,21 +566,16 @@ class Benchmarker:
         self.__cleanup_leftover_processes_before_test();
         self.__cleanup_leftover_processes_before_test();
 
 
         if self.__is_port_bound(test.port):
         if self.__is_port_bound(test.port):
-          # This can happen sometimes - let's try again
-          self.__stop_test(out)
+          # We gave it our all
+          self.__write_intermediate_results(test.name, "port " + str(test.port) + " is not available before start")
+          out.write(header("Error: Port %s is not available, cannot start %s" % (test.port, test.name)))
           out.flush()
           out.flush()
-          time.sleep(15)
-          if self.__is_port_bound(test.port):
-            # We gave it our all
-            self.__write_intermediate_results(test.name, "port " + str(test.port) + " is not available before start")
-            out.write(header("Error: Port %s is not available, cannot start %s" % (test.port, test.name)))
-            out.flush()
-            print "Error: Unable to recover port, cannot start test"
-            return exit_with_code(1)
+          print "Error: Unable to recover port, cannot start test"
+          return exit_with_code(1)
 
 
-        result = test.start(out)
+        result, pgid = test.start(out)
         if result != 0:
         if result != 0:
-          self.__stop_test(out)
+          self.__stop_test(pgid, out)
           time.sleep(5)
           time.sleep(5)
           out.write( "ERROR: Problem starting {name}\n".format(name=test.name) )
           out.write( "ERROR: Problem starting {name}\n".format(name=test.name) )
           out.flush()
           out.flush()
@@ -618,13 +613,13 @@ class Benchmarker:
         ##########################
         ##########################
         out.write(header("Stopping %s" % test.name))
         out.write(header("Stopping %s" % test.name))
         out.flush()
         out.flush()
-        self.__stop_test(out)
+        self.__stop_test(pgid, out)
         out.flush()
         out.flush()
         time.sleep(15)
         time.sleep(15)
 
 
         if self.__is_port_bound(test.port):
         if self.__is_port_bound(test.port):
           # This can happen sometimes - let's try again
           # This can happen sometimes - let's try again
-          self.__stop_test(out)
+          self.__stop_test(pgid, out)
           out.flush()
           out.flush()
           time.sleep(15)
           time.sleep(15)
           if self.__is_port_bound(test.port):
           if self.__is_port_bound(test.port):
@@ -669,7 +664,7 @@ class Benchmarker:
         traceback.print_exc(file=out)
         traceback.print_exc(file=out)
         out.flush()
         out.flush()
         try:
         try:
-          self.__stop_test(out)
+          self.__stop_test(pgid, out)
         except (subprocess.CalledProcessError) as e:
         except (subprocess.CalledProcessError) as e:
           self.__write_intermediate_results(test.name,"<setup.py>#stop() raised an error")
           self.__write_intermediate_results(test.name,"<setup.py>#stop() raised an error")
           out.write(header("Subprocess Error: Test .stop() raised exception %s" % test.name))
           out.write(header("Subprocess Error: Test .stop() raised exception %s" % test.name))
@@ -680,7 +675,7 @@ class Benchmarker:
       # TODO - subprocess should not catch this exception!
       # TODO - subprocess should not catch this exception!
       # Parent process should catch it and cleanup/exit
       # Parent process should catch it and cleanup/exit
       except (KeyboardInterrupt) as e:
       except (KeyboardInterrupt) as e:
-        self.__stop_test(out)
+        self.__stop_test(pgid, out)
         out.write(header("Cleaning up..."))
         out.write(header("Cleaning up..."))
         out.flush()
         out.flush()
         self.__finish()
         self.__finish()
@@ -697,9 +692,9 @@ class Benchmarker:
   # __stop_test(benchmarker)
   # __stop_test(benchmarker)
   # Stops all running tests
   # Stops all running tests
   ############################################################
   ############################################################
-  def __stop_test(self, out):
+  def __stop_test(self, pgid, out):
     try:
     try:
-      subprocess.check_call('sudo kill -9 -%s' % os.getgid(), shell=True, stderr=out, stdout=out)
+      subprocess.check_call('sudo kill -9 -%s' % pgid, shell=True, stderr=out, stdout=out)
       retcode = 0
       retcode = 0
     except Exception:
     except Exception:
       retcode = 1
       retcode = 1

+ 3 - 2
toolset/benchmark/framework_test.py

@@ -198,7 +198,7 @@ class FrameworkTest:
     os.chdir(os.path.dirname(self.troot))
     os.chdir(os.path.dirname(self.troot))
     logging.info("Running setup module start (cwd=%s)", self.directory)
     logging.info("Running setup module start (cwd=%s)", self.directory)
 
 
-    command = 'source %s && source %s.sh' % (
+    command = 'bash -exc "source %s && source %s.sh"' % (
       bash_functions_path,
       bash_functions_path,
       os.path.join(self.troot, self.setup_file))
       os.path.join(self.troot, self.setup_file))
 
 
@@ -241,6 +241,7 @@ class FrameworkTest:
     p = subprocess.Popen(command, cwd=self.directory,
     p = subprocess.Popen(command, cwd=self.directory,
           shell=True, stdout=subprocess.PIPE,
           shell=True, stdout=subprocess.PIPE,
           stderr=subprocess.STDOUT)
           stderr=subprocess.STDOUT)
+    pgid = os.getpgid(p.pid)
     nbsr = setup_util.NonBlockingStreamReader(p.stdout,
     nbsr = setup_util.NonBlockingStreamReader(p.stdout,
       "%s: %s.sh and framework processes have terminated" % (self.name, self.setup_file))
       "%s: %s.sh and framework processes have terminated" % (self.name, self.setup_file))
 
 
@@ -337,7 +338,7 @@ class FrameworkTest:
     logging.info("Executed %s.sh, returning %s", self.setup_file, retcode)
     logging.info("Executed %s.sh, returning %s", self.setup_file, retcode)
     os.chdir(previousDir)
     os.chdir(previousDir)
 
 
-    return retcode
+    return retcode, pgid
   ############################################################
   ############################################################
   # End start
   # End start
   ############################################################
   ############################################################