Run until we receive a shutdown/reload signal,
 or when the worker raises an Interrupt.
 Runs after a fork when Revenant::Daemon is enabled.
346874
def run_loop(&block)
      acquired = false
      begin
        until shutdown_pending?
          # The usual situation
          if relock_every != 0
            i ||= 0
            # 0 % anything is 0, so we always try to get the lock on the first loop.
            if (i %= relock_every) == 0
              acquired = lock_function.call(@name)
            end
          else
            # With relock_every set to 0, only acquire the lock once.
            # Hope you're sure that lock beongs to you.
            acquired ||= lock_function.call(@name)
            i = 0 # no point in incrementing something we don't check.
          end

          yield if acquired

          # Sleep one second at a time so we can quickly respond to
          # shutdown requests.
          sleep_for.times do
            sleep(1) unless shutdown_pending?
          end
          i += 1
        end # loop
      rescue ::Interrupt => ex
        log "shutting down after interrupt: #{ex.class} - #{ex.message}"
        shutdown_soon # Always shut down from an Interrupt, even mid-restart.
        return
      rescue ::Exception => ex
        error "restarting after error: #{ex.class} - #{ex.message}"
        error "backtrace: #{ex.backtrace.join("\n")}"
        restart_soon # Restart if we run into an exception.
      end # begin block
    end
540102
protected void checkShutdownInterval ()
    {
        // queue up a shutdown interval, unless we've already got one.
        long idlePeriod = idleUnloadPeriod();
        if (idlePeriod > 0L && _shutdownInterval == null) {
            (_shutdownInterval = _omgr.newInterval(new Runnable() {
                public void run () {
                    log.debug("Unloading idle place '" + where() + "'.");
                    shutdown();
                }
            })).schedule(idlePeriod);
        }
    }
1237503
def burn_down_workers(signal)
      loop do
        check_for_expired_workers
        write_procline('shutdown')
        SIGNAL_QUEUE.clear

        break if :no_child == reap_workers(Process::WNOHANG)
        kill_all(signal)

        sleep 1 # Don't kill any more often than every 1s.
        yawn 5
      end
      # One last time.
      reap_workers
    end
630858
def run(self):
        
        self._initialize()

        self._do_collect()
        while not self._is_finished:
            time.sleep(self._reload_interval)
            self._do_collect()

        self.logger.info("Collector stopped.")
321629
public void shutdown()
  {
    log.info("Shutting down...");
    isShutdownRequested = true;

    try
    {
      mainThread.join();
    }
    catch (InterruptedException e)
    {
      log.error(
        "Interrupted which waiting on main daemon thread to complete.");
    }
  }
1117014
def run(self):
        
        listener_thr = _spawn(self.receiver.run)
        callback_thr = _spawn(self.callbacks.run)
        sender_thr = _spawn(self.sender.run)
        logger_thr = _spawn(self.logger.run)

        self.connect()
        try:
            yield
        finally:
            self.stop()

            # Wait for the listener to finish.
            listener_thr.join()
            self.callbacks.put('shutdown')

            # Tell the other threads to finish, and wait for them.
            for obj in [self.callbacks, self.sender, self.logger]:
                obj.stop()
            for thr in [callback_thr, sender_thr, logger_thr]:
                thr.join()
776845
public function run()
    {

        try {
            // register shutdown handler
            register_shutdown_function($this->getDefaultShutdownMethod());

            // bootstrap the daemon
            $this->bootstrap();

            // invoke the execute method
            try {
                $this->execute();
            } catch (\Exception $e) {
                $this->log(LogLevel::ERROR, $e->__toString());
            }

            // clean up the instances and free memory
            $this->cleanUp();

        } catch (\Exception $e) {
            $this->log(LogLevel::ERROR, $e->__toString());
        }
    }
105448
def run(self, asynchronous=False):
        '''
        
        '''
        log.debug('Process Manager starting!')
        appendproctitle(self.name)

        # make sure to kill the subprocesses if the parent is killed
        if signal.getsignal(signal.SIGTERM) is signal.SIG_DFL:
            # There are no SIGTERM handlers installed, install ours
            signal.signal(signal.SIGTERM, self.kill_children)
        if signal.getsignal(signal.SIGINT) is signal.SIG_DFL:
            # There are no SIGINT handlers installed, install ours
            signal.signal(signal.SIGINT, self.kill_children)

        while True:
            log.trace('Process manager iteration')
            try:
                # in case someone died while we were waiting...
                self.check_children()
                # The event-based subprocesses management code was removed from here
                # because os.wait() conflicts with the subprocesses management logic
                # implemented in `multiprocessing` package. See #35480 for details.
                if asynchronous:
                    yield gen.sleep(10)
                else:
                    time.sleep(10)
                if not self._process_map:
                    break
            # OSError is raised if a signal handler is called (SIGTERM) during os.wait
            except OSError:
                break
            except IOError as exc:
                # IOError with errno of EINTR (4) may be raised
                # when using time.sleep() on Windows.
                if exc.errno != errno.EINTR:
                    raise
                break
444575
def send_signal(self, s):
        
        self._get_signal_event(s)  # Check if signal has been enabled
        pid = self.get_pid()
        if not pid:
            raise ValueError('Daemon is not running.')
        os.kill(pid, s)
384953
def reopen_after_fork!
    logger.debug { "#{self.class}##{__method__} fork detected!" } if forked?

    @mutex = Monitor.new
    @dispatch_shutdown_cond = @mutex.new_cond
    @event_queue = QueueWithPipe.new

    @dispatcher = nil if @dispatcher and not @dispatcher.alive?

    update_pid!  # from Forked
  end
783326
def start(ctx, **kwargs):
    
    update_context(ctx, kwargs)

    daemon = mk_daemon(ctx)

    if ctx.debug or kwargs['no_fork']:
        daemon.run()
    else:
        daemon.start()
716734
def reopen_after_fork!
#       logger.debug { "#{self.class}##{__method__}" }

      unless @state == :paused
        raise InvalidStateError, "state should have been :paused, not: #{@state.inspect}"
      end

      if @thread 
        raise InvalidStateError, "WTF?! did you fork in a callback? my thread was alive!" if @thread.alive?
        @thread = nil
      end

      @mutex  = Mutex.new
      @cond   = ConditionVariable.new
      @array  = []
      resume_after_fork_in_parent
    end
717921
def run_once(self):
        
        self._capture_signals()
        self._start_monitor()
        try:
            self._run_worker()
        except KeyboardInterrupt:
            return
        finally:
            self._stop_monitor()
            self._restore_signals()
60441
def runAndWait(self):
        '''
        
        '''
        self._push(self._engine.endLoop, tuple())
        self._driver.startLoop()
1311457
void stopReload() throws InterruptedException {
    if (reloadThread != null) {
      running = false;
      reloadThread.interrupt();
      reloadThread.join();
      reloadThread = null;
    }
  }
441237
def _runForever(self, stop_event):
        
        while(not stop_event.is_set()):
            state = self.pusher.connection.state

            if (state is not "connecting" and
                    state is not "connected"):
                self.logger.warning(
                    "Pusher seems to be disconnected, trying to reconnect")
                self.pusher.connect()

            stop_event.wait(0.5)
607089
def run(self):
        '''
        
        '''
        salt.utils.process.appendproctitle(self.__class__.__name__)

        # init things that need to be done after the process is forked
        self._post_fork_init()

        # Make Start Times
        last = int(time.time())

        old_present = set()
        while True:
            now = int(time.time())
            if (now - last) >= self.loop_interval:
                salt.daemons.masterapi.clean_old_jobs(self.opts)
                salt.daemons.masterapi.clean_expired_tokens(self.opts)
                salt.daemons.masterapi.clean_pub_auth(self.opts)
                salt.daemons.masterapi.clean_proc_dir(self.opts)
            self.handle_git_pillar()
            self.handle_schedule()
            self.handle_key_cache()
            self.handle_presence(old_present)
            self.handle_key_rotate(now)
            salt.utils.verify.check_max_open_files(self.opts)
            last = now
            time.sleep(self.loop_interval)