Terminate the sub-process.
494832
def _shutdown(self):
    """"""
    if self._proc:
      ret = _shutdown_proc(self._proc, 3)
      logging.info("Shutdown with return code: %s", ret)
      self._proc = None
151939
def close(self):
        '''
        '''
        if not self._process:
            return

        if self._process.returncode is not None:
            return

        _logger.debug('Terminate process.')

        try:
            self._process.terminate()
        except OSError as error:
            if error.errno != errno.ESRCH:
                raise

        for dummy in range(10):
            if self._process.returncode is not None:
                return

            time.sleep(0.05)

        _logger.debug('Failed to terminate. Killing.')

        try:
            self._process.kill()
        except OSError as error:
            if error.errno != errno.ESRCH:
                raise
314598
def _kill(self, kill_sig):
    """"""
    if self.pid:
      os.kill(self.pid, kill_sig)
1008116
def terminate(self):
        """"""
        if self._process.state() == QProcess.Running:
            try:
                self._process.terminate()
            except Exception:
                pass
        self._fired = True
161808
def kill_process(procname, scriptname):
    """"""

    # from http://stackoverflow.com/a/2940878
    import signal
    import subprocess

    p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
    out, err = p.communicate()

    for line in out.decode().splitlines():
        if procname in line and scriptname in line:
            pid = int(line.split()[1])
            info('Stopping %s %s %d' % (procname, scriptname, pid))
            os.kill(pid, signal.SIGKILL)
1183425
def _terminate_procs(procs):
    
    logging.warn("Stopping all remaining processes")
    for proc, g in procs.values():
        logging.debug("[%s] SIGTERM", proc.pid)
        try:
            proc.terminate()
        except OSError as e:
            # we don't care if the process we tried to kill didn't exist.
            if e.errno != errno.ESRCH:
                raise
    sys.exit(1)
344608
def stop(self):
        
        if self._stack:
            try:
                self._stack.teardown()
            except Exception:
                self.fatal(sys.exc_info())

        super().stop()
427200
public function abandon()
    {
        foreach ($this->processes as $index => $process) {
            $process->kill();

            unset($process[$index]);
        }

        unset($this->processes);
    }
1284608
def terminate(self):
    """"""
    # Tear down the Pailgun TCPServer.
    if self.pailgun:
      self.pailgun.server_close()

    super(PailgunService, self).terminate()
137864
def kill(self):
        """"""
        if not self.is_dead():
            self.bundle_engine.warnline("{0} did not shut down cleanly, killing.".format(self.service.name))
            try:
                if hasattr(self.process, 'pid'):
                    for child in psutil.Process(self.process.pid).children(recursive=True):
                        os.kill(child.pid, signal.SIGKILL)
                    self.process.kill()
            except psutil.NoSuchProcess:
                pass
1277543
async def close(self, timeout=5) -> None:
        """"""
        if not self.is_running:
            _LOGGER.warning("FFmpeg isn't running!")
            return

        # Can't use communicate because we attach the output to a streamreader
        def _close():
            """Close ffmpeg."""
            self._proc.stdin.write(b"q")
            self._proc.wait(timeout=timeout)

        # send stop to ffmpeg
        try:
            await self._loop.run_in_executor(None, _close)
            _LOGGER.debug("Close FFmpeg process")

        except (subprocess.TimeoutExpired, ValueError):
            _LOGGER.warning("Timeout while waiting of FFmpeg")
            self.kill()

        finally:
            self._clear()
241117
def stop(self):
        """"""
        logger.info("stopping process")
        self.watcher.stop()
        os.kill(self.child_pid, signal.SIGTERM)
634397
def terminate(self, signal_chain=KILL_CHAIN, kill_wait=KILL_WAIT_SEC, purge=True):
    """"""
    alive = self.is_alive()
    if alive:
      logger.debug('terminating {}'.format(self._name))
      for signal_type in signal_chain:
        pid = self.pid
        try:
          logger.debug('sending signal {} to pid {}'.format(signal_type, pid))
          self._kill(signal_type)
        except OSError as e:
          logger.warning('caught OSError({e!s}) during attempt to kill -{signal} {pid}!'
                         .format(e=e, signal=signal_type, pid=pid))

        # Wait up to kill_wait seconds to terminate or move onto the next signal.
        try:
          if self._deadline_until(self.is_dead, 'daemon to exit', timeout=kill_wait):
            alive = False
            logger.debug('successfully terminated pid {}'.format(pid))
            break
        except self.Timeout:
          # Loop to the next kill signal on timeout.
          pass

    if alive:
      raise ProcessManager.NonResponsiveProcess('failed to kill pid {pid} with signals {chain}'
                                      .format(pid=self.pid, chain=signal_chain))

    if purge:
      self.purge_metadata(force=True)
969802
def shutdown(self):
        """"""
        # cleanup
        self.started = False
        try:
            # nice way of doing things - let's wait until all items
            # in the queue are processed
            for t in self._threads:
                t.join()
        finally:
            # Emergency brake - if a KeyboardInterrupt is raised,
            # threads will finish processing current task and exit
            self.stopped = True
983982
def stop(self):
        """"""
        if self.thread:
            self.running = False
            if isinstance(self.stream, ReadWriteStream):
                self.stream.write(b'\0' * self.chunk_size)
            self.thread.join()
            self.thread = None

        self.engine.stop()

        if self.pa:
            self.pa.terminate()
            self.stream.stop_stream()
            self.stream = self.pa = None
950154
def kill(self):
        
        BaseShellOperator._close_process_input_stdin(self._batcmd.batch_to_file_s)
        BaseShellOperator._wait_process(self._process, self._batcmd.sh_cmd, self._success_exitcodes)
        BaseShellOperator._rm_process_input_tmpfiles(self._batcmd.batch_to_file_s)
        self._process = None
478795
def close(self):
        """"""
        if self._proc is not None:
            self._proc.stdin.close()
            self._proc.wait()