politely ask the process to stop, and wait for it to exit
18697
def stop
      return self if @pid.nil?
      _log "stopping (##{@pid})"
      Process.kill('INT', @pid)

      Timeout::timeout(10) do
        sleep(10e-3) until Process.wait(@pid, Process::WNOHANG)
        @status = $?
      end

      @pid = nil
      self
    end
1030317
def _wait_for_machine_finish(self, name):
        
        # TODO: rewrite it using probes module in utils
        for foo in range(constants.DEFAULT_RETRYTIMEOUT):
            time.sleep(constants.DEFAULT_SLEEP)
            out = run_cmd(
                ["machinectl", "--no-pager", "status", name],
                ignore_status=True, return_output=True)
            if out != 0:
                return True
        raise ConuException(
            "Unable to stop machine %s within %d" %
            (name, constants.DEFAULT_RETRYTIMEOUT))
1365106
def stop(self, sig=signal.SIGTERM):
        

        if self.pid is None:
            self.pid = self.read_pid()
        if self.pid is None:
            sp = BackgroundProcess.objects.filter(pk=1).first()
            if sp:
                self.pid = sp.pid
        if self.pid is None or self.pid == 0:
            logger.error("can't determine process id exiting.")
            return False
        if self.pid != getpid():
            # calling from outside the daemon instance
            logger.debug('send sigterm to daemon')
            try:
                kill(self.pid, sig)
                return True
            except OSError as e:
                if e.errno == errno.ESRCH:
                    return False
                else:
                    return False

        logger.debug('start termination of the daemon')
        BackgroundProcess.objects.filter(pk=self.process_id).update(
            last_update=now(),
            message='stopping..')

        timeout = time() + 60  # wait max 60 seconds
        self.kill_processes(signal.SIGTERM)
        while self.PROCESSES and time() < timeout:
            self.kill_processes(signal.SIGTERM)
            sleep(1)
        self.kill_processes(signal.SIGKILL)
        BackgroundProcess.objects.filter(pk=self.process_id).update(
            last_update=now(),
            message='stopped')
        logger.debug('termination of the daemon done')
        return True
1295300
def stop(self) -> None:
        
        if not self.running:
            return
        try:
            self.wait(timeout_s=0)
            # If we get here: stopped already
        except subprocess.TimeoutExpired:  # still running
            for kill_level in self.ALL_KILL_LEVELS:
                tried_to_kill = self._terminate(level=kill_level)  # please stop
                if tried_to_kill:
                    try:
                        self.wait(timeout_s=self.kill_timeout_sec)
                        break
                    except subprocess.TimeoutExpired:  # failed to close
                        self.warning("Subprocess didn't stop when asked")
                        pass  # carry on escalating
        self.close_logs()
        self.running = False
922718
def wait(self, timeout=None):
        
        try:
            if timeout:
                gevent.sleep(timeout)
            else:
                while True:
                    gevent.sleep(1000)
        except (KeyboardInterrupt, SystemExit, Exception):
            pass
1299921
function later (info) {
	process.stdin.resume();
	const action = start.bind(null, info);
	process.on('SIGINT', action);
	process.on('SIGTERM', action);

	(function wait () {
		if (beenthere) {
			return;
		}

		setTimeout(wait, EVENT_LOOP);
	}());
}
334074
def pause():
	""""""

	if not settings.platformCompatible():
		return False

	(output, error) = subprocess.Popen(["osascript", "-e", PAUSE], stdout=subprocess.PIPE).communicate()
685688
def _close(self):
        """"""
        self.client.stop()
        self.open = False
        self.waiting = False
756119
def stop(self, wait=True):
        
        logger.info("Primitive %s stopped.", self)
        StoppableThread.stop(self, wait)
105075
def wait(self):
        """"""
        self._returncode = self.process.wait()
        try:
            self.process.stderr.close()
        except:
            pass
        self.set_status(self.S_DONE, "status set to Done")

        return self._returncode
436541
async def stop(self):
        """"""

        if self._rpc_task is not None:
            self._rpc_task.cancel()

        try:
            await self._rpc_task
        except asyncio.CancelledError:
            pass

        self._rpc_task = None
51872
async def stop(self, wait_for_completion=True):
        
        await self.set_position(
            position=CurrentPosition(),
            wait_for_completion=wait_for_completion)
357570
def wait_stop(self):
        
        if not self.running:
            return
        self.stop()
        try:
            yield from self._task
        except asyncio.CancelledError:
            pass
729494
def stop(self, wait=True):
        ''' 

        '''

        # TODO should probably close all connections and shut down all sessions here
        for context in self._applications.values():
            context.run_unload_hook()

        self._stats_job.stop()
        if self._mem_job is not None:
            self._mem_job.stop()
        self._cleanup_job.stop()
        if self._ping_job is not None:
            self._ping_job.stop()

        self._clients.clear()
386116
def stop(self):
        
        if self.log_file != PIPE and not (self.log_file == DEVNULL and _HAS_NATIVE_DEVNULL):
            try:
                self.log_file.close()
            except Exception:
                pass

        if self.process is None:
            return

        try:
            self.send_remote_shutdown_command()
        except TypeError:
            pass

        try:
            if self.process:
                for stream in [self.process.stdin,
                               self.process.stdout,
                               self.process.stderr]:
                    try:
                        stream.close()
                    except AttributeError:
                        pass
                self.process.terminate()
                self.process.wait()
                self.process.kill()
                self.process = None
        except OSError:
            pass
258346
def halt(self):
        
        if self._callback:
            self._thread_continue = False
            self._thread.join()
55284
def pause_process(self, key):
        """"""
        if key in self.processes and key not in self.paused:
            os.killpg(os.getpgid(self.processes[key].pid), signal.SIGSTOP)
            self.queue[key]['status'] = 'paused'
            self.paused.append(key)
            return True
        return False