Stops monitoring a process.

    Args:
      process (MultiProcessBaseProcess): process.

    Raises:
      KeyError: if the process is not monitored.
      ValueError: if the process is missing.
492932
def _StopMonitoringProcess(self, process):
    
    if process is None:
      raise ValueError('Missing process.')

    pid = process.pid

    self._RaiseIfNotMonitored(pid)

    del self._process_information_per_pid[pid]

    rpc_client = self._rpc_clients_per_pid.get(pid, None)
    if rpc_client:
      rpc_client.Close()
      del self._rpc_clients_per_pid[pid]

    if pid in self._rpc_errors_per_pid:
      del self._rpc_errors_per_pid[pid]

    logger.debug('Stopped monitoring process: {0:s} (PID: {1:d})'.format(
        process.name, pid))
158538
def stop(self, timeout=15):
        
        pp = self.pid
        if pp:
            try:
                kill_process_nicely(pp, timeout=timeout)
            except psutil.NoSuchProcess:
                pass
1220834
def close(self):
        
        if self._process:
            # Be nice first.
            self._process.send_signal(signal.SIGINT)

            # If it doesn't close itself promptly, be brutal.
            # Python 3.2+ added the timeout option to wait() and the
            # corresponding TimeoutExpired exception. If they exist, use them.
            if hasattr(subprocess, 'TimeoutExpired'):
                try:
                    self._process.wait(timeout=1)
                except subprocess.TimeoutExpired:
                    self._process.send_signal(signal.SIGKILL)

            # Otherwise, roll our own polling loop.
            else:
                # Give it 1s, checking every 10ms.
                count = 0
                while count < 100:
                    if self._process.poll() is not None:
                        break
                    time.sleep(0.01)

                # Still hasn't quit.
                if self._process.poll() is None:
                    self._process.send_signal(signal.SIGKILL)

            # Clean up.
            self._process = None
8444
def stop(self):
        
        if self.pid is None:

            return None

        try:

            while True:

                self.send(signal.SIGTERM)
                time.sleep(0.1)

        except RuntimeError as err:

            if "No such process" in str(err):

                LOG.info("Succesfully stopped the process.")
                return None

            LOG.exception("Failed to stop the process:")
            sys.exit(exit.STOP_FAILED)

        except TypeError as err:

            if "an integer is required" in str(err):

                LOG.info("Succesfully stopped the process.")
                return None

            LOG.exception("Failed to stop the process:")
            sys.exit(exit.STOP_FAILED)
533812
def close_process_handles(self):
        
        for pid in self.get_process_ids():
            aProcess = self.get_process(pid)
            try:
                aProcess.close_handle()
            except Exception:
                e = sys.exc_info()[1]
                try:
                    msg = "Cannot close process handle %s, reason: %s"
                    msg %= (aProcess.hProcess.value, str(e))
                    warnings.warn(msg)
                except Exception:
                    pass
203932
def stop(self):
        

        if self.is_running():
            log.info("Stopping Dynamips process PID={}".format(self._process.pid))
            yield from DynamipsHypervisor.stop(self)
            # give some time for the hypervisor to properly stop.
            # time to delete UNIX NIOs for instance.
            yield from asyncio.sleep(0.01)
            try:
                yield from wait_for_process_termination(self._process, timeout=3)
            except asyncio.TimeoutError:
                if self._process.returncode is None:
                    log.warn("Dynamips process {} is still running... killing it".format(self._process.pid))
                    try:
                        self._process.kill()
                    except OSError as e:
                        log.error("Cannot stop the Dynamips process: {}".format(e))
                    if self._process.returncode is None:
                        log.warn('Dynamips hypervisor with PID={} is still running'.format(self._process.pid))

        if self._stdout_file and os.access(self._stdout_file, os.W_OK):
            try:
                os.remove(self._stdout_file)
            except OSError as e:
                log.warning("could not delete temporary Dynamips log file: {}".format(e))
        self._started = False
359200
def stop(self):
        
        if hasattr(sys, "gettrace") and self.log:
            if sys.gettrace() != self._trace:
                msg = "Trace function changed, measurement is likely wrong: %r"
                print >> sys.stdout, msg % sys.gettrace()
        sys.settrace(None)
426492
def stop(self, sig=None, timeout=10):
        
        if self.process is None:
            return self

        if sig is None:
            sig = self._sig_stop

        try:
            os.killpg(self.process.pid, sig)
        except OSError as err:
            if err.errno in IGNORED_ERROR_CODES:
                pass
            else:
                raise

        def process_stopped():
            """Return True only only when self.process is not running."""
            return self.running() is False

        self._set_timeout(timeout)
        try:
            self.wait_for(process_stopped)
        except TimeoutExpired:
            log.warning('Timeout expired, killing process', process=self)
            pass

        self._kill_all_kids(sig)
        self._clear_process()
        return self
1365592
def finalize_processes(self):
        # type: (_MultiprocessOffload) -> None
        
        self._term_signal.value = 1
        if self._check_thread is not None:
            self._check_thread.join()
        for proc in self._procs:
            proc.join()
469943
def _TerminateProcessByPid(self, pid):
    
    self._RaiseIfNotRegistered(pid)

    process = self._processes_per_pid[pid]

    self._TerminateProcess(process)
    self._StopMonitoringProcess(process)
1249237
def cancel(self):
        """"""
        if self.__process.is_alive():
            self.__process.terminate()

        _raise_exception(self.__timeout_exception, self.__exception_message)
980745
def stop(self):
        
        # unsetup_fuse()
        self.fuse_process.teardown()
        for uuid in self.processes:
            self.processes[uuid].terminate()
1124754
def _CheckStatusAnalysisProcess(self, pid):
    
    # TODO: Refactor this method, simplify and separate concerns (monitoring
    # vs management).
    self._RaiseIfNotRegistered(pid)

    if pid in self._completed_analysis_processes:
      status_indicator = definitions.STATUS_INDICATOR_COMPLETED
      process_status = {
          'processing_status': status_indicator}
      used_memory = 0

    else:
      process = self._processes_per_pid[pid]

      process_status = self._QueryProcessStatus(process)
      if process_status is None:
        process_is_alive = False
      else:
        process_is_alive = True

      process_information = self._process_information_per_pid[pid]
      used_memory = process_information.GetUsedMemory() or 0

      if self._worker_memory_limit and used_memory > self._worker_memory_limit:
        logger.warning((
            'Process: {0:s} (PID: {1:d}) killed because it exceeded the '
            'memory limit: {2:d}.').format(
                process.name, pid, self._worker_memory_limit))
        self._KillProcess(pid)

      if isinstance(process_status, dict):
        self._rpc_errors_per_pid[pid] = 0
        status_indicator = process_status.get('processing_status', None)

        if status_indicator == definitions.STATUS_INDICATOR_COMPLETED:
          self._completed_analysis_processes.add(pid)

      else:
        rpc_errors = self._rpc_errors_per_pid.get(pid, 0) + 1
        self._rpc_errors_per_pid[pid] = rpc_errors

        if rpc_errors > self._MAXIMUM_RPC_ERRORS:
          process_is_alive = False

        if process_is_alive:
          rpc_port = process.rpc_port.value
          logger.warning((
              'Unable to retrieve process: {0:s} (PID: {1:d}) status via '
              'RPC socket: http://localhost:{2:d}').format(
                  process.name, pid, rpc_port))

          processing_status_string = 'RPC error'
          status_indicator = definitions.STATUS_INDICATOR_RUNNING
        else:
          processing_status_string = 'killed'
          status_indicator = definitions.STATUS_INDICATOR_KILLED

        process_status = {
            'processing_status': processing_status_string}

    self._UpdateProcessingStatus(pid, process_status, used_memory)

    if status_indicator in definitions.ERROR_STATUS_INDICATORS:
      logger.error((
          'Process {0:s} (PID: {1:d}) is not functioning correctly. '
          'Status code: {2!s}.').format(
              process.name, pid, status_indicator))

      self._TerminateProcessByPid(pid)
1176684
def stop(self):
    """"""

    log.info('Stopping %s' % self)

    pids = list(self._processes)

    # Clean up the context
    for pid in pids:
      self.terminate(pid)

    while self._connections:
      pid = next(iter(self._connections))
      conn = self._connections.pop(pid, None)
      if conn:
        conn.close()

    self.__loop.stop()
862813
def stop_cont(self, cont=True):
        
        for proc in psutil.process_iter():
            if proc.name() == self.process_name:
                sig = psutil.signal.SIGCONT if cont else psutil.signal.SIGSTOP
                proc.send_signal(sig)
                if self.debug:
                    sig = 'CONT' if cont else 'STOP'
                    print("Sent SIG%s to process %d" % (sig, proc.pid))
178475
def stop_process(self):
        
        if self.process is not None:
            self._user_stop = True
            self.process.kill()
            self.setReadOnly(True)
            self._running = False
1103570
def _KillProcess(self, pid):
    
    if sys.platform.startswith('win'):
      process_terminate = 1
      handle = ctypes.windll.kernel32.OpenProcess(
          process_terminate, False, pid)
      ctypes.windll.kernel32.TerminateProcess(handle, -1)
      ctypes.windll.kernel32.CloseHandle(handle)

    else:
      try:
        os.kill(pid, signal.SIGKILL)
      except OSError as exception:
        logger.error('Unable to kill process {0:d} with error: {1!s}'.format(
            pid, exception))