def dummy_testplan(request): """ Start the dummy testplan in a separate process. Terminate the dummy testplan and wait for the process to end. """ cmd = [sys.executable] + request.param cwd = os.path.dirname(os.path.abspath(__file__)) testplan_proc = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE) # Set up a thread to read from the process' stdout and write to a queue. # This prevents the main thread from blocking when there is no output. stdout_queue = queue.Queue() thr = threading.Thread(target=_enqueue_output, args=(testplan_proc.stdout, stdout_queue)) thr.daemon = True thr.start() yield testplan_proc, stdout_queue if testplan_proc.poll() is None: kill_process(testplan_proc) assert testplan_proc.poll() is not None thr.join(timeout=_TIMEOUT) assert(not thr.is_alive())
def aborting(self): """Abort logic to force kill the child binary.""" if self.proc: self.logger.debug("Killing process id {}".format(self.proc.pid)) kill_process(self.proc) if self.std: self.std.close()
def stopping(self): """Stop child process worker.""" self._transport.active = False if self._handler: kill_process(self._handler) self._handler.wait() self.status.change(self.STATUS.STOPPED)
def aborting(self): """Process worker abort logic.""" self._transport.disconnect() if hasattr(self, '_handler') and self._handler: kill_process(self._handler) self._handler.wait() self._handler = None
def dummy_testplan(request): """ Start the dummy testplan in a separate process. Terminate the dummy testplan and wait for the process to end. """ cmd = [sys.executable] + request.param cwd = os.path.dirname(os.path.abspath(__file__)) testplan_proc = subprocess.Popen(cmd, cwd=cwd) yield testplan_proc kill_process(testplan_proc)
def stopping(self): """Stop remote rpyc process""" remote_pid = self.rpyc_connection.modules.os.getpid() try: self.rpyc_connection.modules.os.kill(remote_pid, signal.SIGTERM) except EOFError: pass # actually if remote rpyc server is shutdown, ssh proc is also finished # but calling kill_process just in case if self.proc: kill_process(self.proc) self.proc.wait() self.status.change(self.STATUS.STOPPED)
def starting(self): """Starts the application binary.""" super(App, self).starting() cmd = " ".join(self.cmd) if self.cfg.shell else self.cmd cwd = self.cfg.working_dir or self.runpath try: self.logger.debug( "%(driver)s driver command: %(cmd)s\n" "\tRunpath: %(runpath)s\n" "\tOut file: %(out)s\n" "\tErr file: %(err)s\n", { "driver": self.uid(), "cmd": cmd, "runpath": self.runpath, "out": self.std.out_path, "err": self.std.err_path, }, ) self.proc = subprocess_popen( cmd, shell=self.cfg.shell, stdin=subprocess.PIPE, stdout=self.std.out, stderr=self.std.err, cwd=cwd, env=self.env, ) except Exception: self.logger.error( "Error while App[%s] driver executed command: %s", self.cfg.name, cmd if self.cfg.shell else " ".join(cmd), ) if self.proc is not None: if self.proc.poll() is None: kill_process(self.proc) assert self.proc.returncode is not None self._proc = None raise
def stopping(self): """Stops the application binary process.""" super(App, self).stopping() try: self._retcode = kill_process(self.proc) except Exception as exc: warnings.warn('On killing driver {} process - {}'.format( self.cfg.name, exc)) self._retcode = self.proc.poll() self.proc = None if self.std: self.std.close()
def stopping(self): """Stops the application binary process.""" super(App, self).stopping() # if self.proc is None: return try: self._retcode = kill_process(self.proc) except Exception as exc: warnings.warn("On killing driver {} process - {}".format( self.cfg.name, exc)) self._retcode = self.proc.poll() if self.proc else 0 self.proc = None if self.std: self.std.close() self._log_matcher = None
def stopping(self): """Stops the application binary process.""" super(App, self).stopping() # if self.proc is None: return try: self._retcode = kill_process(self.proc) except Exception as exc: warnings.warn("On killing driver {} process - {}".format( self.cfg.name, exc)) self._retcode = self.proc.poll() if self.proc else 0 self.proc = None if self.std: self.std.close() self._log_matcher = None if (self.cfg.expected_retcode is not None) and (self.cfg.expected_retcode != self.retcode): err_msg = (f"App driver error: {self.name}," f" expected return code is {self.cfg.expected_retcode}," f" but actual return code is {self.retcode}") raise RuntimeError(err_msg)
def aborting(self): if self._test_process is not None: kill_process(self._test_process) self._test_process_killed = True
def stopping(self): """Stop child process worker.""" if self._handler: kill_process(self._handler) self._handler.wait() self.status.change(self.STATUS.STOPPED)
def stopping(self): """Stop child process worker.""" if hasattr(self, "_handler") and self._handler: kill_process(self._handler) self.status.change(self.STATUS.STOPPED)
def aborting(self): kill_process(self._test_process) self._test_process_killed = True
def aborting(self): """Process worker abort logic.""" self._transport.active = False if self._handler: kill_process(self._handler) self._handler.wait()