Exemplo n.º 1
0
 def test_kill_process_with_children(self):
   if _platform == "linux" or _platform == "linux2": # Test is Linux-specific
     gracefull_kill_delay_old = shell.gracefull_kill_delay
     shell.gracefull_kill_delay = 0.1
     sleep_cmd = "sleep 314159265"
     test_cmd = """ (({0}) & ({0} & {0})) """.format(sleep_cmd)
     # Starting process tree (multiple process groups)
     test_process = subprocess.Popen(test_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
     time.sleep(0.3) # Delay to allow subprocess to start
     # Check if processes are running
     ps_cmd = """ps auxww """
     ps_process = subprocess.Popen(ps_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
     (out, err) = ps_process.communicate()
     self.assertTrue(sleep_cmd in out)
     # Kill test process
     shell.kill_process_with_children(test_process.pid)
     test_process.communicate()
     # Now test process should not be running
     ps_process = subprocess.Popen(ps_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
     (out, err) = ps_process.communicate()
     self.assertFalse(sleep_cmd in out)
     shell.gracefull_kill_delay = gracefull_kill_delay_old
   else:
     # Do not run under other systems
     pass
Exemplo n.º 2
0
 def test_kill_process_with_children(self):
   if _platform == "linux" or _platform == "linux2": # Test is Linux-specific
     gracefull_kill_delay_old = shell.gracefull_kill_delay
     shell.gracefull_kill_delay = 0.1
     sleep_cmd = "sleep 314159265"
     test_cmd = """ (({0}) & ({0} & {0})) """.format(sleep_cmd)
     # Starting process tree (multiple process groups)
     test_process = subprocess.Popen(test_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
     time.sleep(0.3) # Delay to allow subprocess to start
     # Check if processes are running
     ps_cmd = """ps aux """
     ps_process = subprocess.Popen(ps_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
     (out, err) = ps_process.communicate()
     self.assertTrue(sleep_cmd in out)
     # Kill test process
     shell.kill_process_with_children(test_process.pid)
     test_process.communicate()
     # Now test process should not be running
     ps_process = subprocess.Popen(ps_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
     (out, err) = ps_process.communicate()
     self.assertFalse(sleep_cmd in out)
     shell.gracefull_kill_delay = gracefull_kill_delay_old
   else:
     # Do not run under other systems
     pass
Exemplo n.º 3
0
 def python_watchdog_func(self, python, timeout):
     self.event.wait(timeout)
     if python.returncode is None:
         logger.error("Subprocess timed out and will be killed")
         shell.kill_process_with_children(python.pid)
         self.python_process_has_been_killed = True
     pass
 def python_watchdog_func(self, python, timeout):
   self.event.wait(timeout)
   if python.returncode is None:
     logger.error("Subprocess timed out and will be killed")
     shell.kill_process_with_children(python.pid)
     self.python_process_has_been_killed = True
   pass
Exemplo n.º 5
0
 def python_watchdog_func(self, process, timeout):
     self.event.wait(timeout)
     if process.returncode is None:
         self.logger.error(
             "Executed command with pid {} timed out and will be killed".
             format(process.pid))
         shell.kill_process_with_children(process.pid)
         self.python_process_has_been_killed = True
 def cancel_command(self, task_id, reason):
   with self.commands_in_progress_lock:
     if task_id in self.commands_in_progress.keys():
       pid = self.commands_in_progress.get(task_id)
       self.commands_in_progress[task_id] = reason
       logger.info("Canceling command with task_id - {tid}, " \
                   "reason - {reason} . Killing process {pid}"
                   .format(tid=str(task_id), reason=reason, pid=pid))
       shell.kill_process_with_children(pid)
     else: 
       logger.warn("Unable to find pid by taskId = %s" % task_id)
Exemplo n.º 7
0
 def cancel_command(self, task_id, reason):
     with self.commands_in_progress_lock:
         if task_id in self.commands_in_progress.keys():
             pid = self.commands_in_progress.get(task_id)
             self.commands_in_progress[task_id] = reason
             logger.info("Canceling command with task_id - {tid}, " \
                         "reason - {reason} . Killing process {pid}"
                         .format(tid=str(task_id), reason=reason, pid=pid))
             shell.kill_process_with_children(pid)
         else:
             logger.warn("Unable to find pid by taskId = %s" % task_id)
Exemplo n.º 8
0
 def watchdog_func(command):
     event.wait(TIMEOUT_SECONDS)
     if command.returncode is None:
         logger.error("Task timed out and will be killed")
         shell.kill_process_with_children(command.pid)
     pass
 def watchdog_func(command):
   event.wait(TIMEOUT_SECONDS)
   if command.returncode is None:
     logger.error("Task timed out and will be killed")
     shell.kill_process_with_children(command.pid)
   pass