Schedule a worker for shutdown. Will finish processing the current job
and when the timeout interval is reached, the worker will shut down.
435168
public function stop()
    {
        $this->shutdown = true;
        if($this->getProcess()->getPid() == getmypid()) {
            $this->getLogger()->notice('Worker {worker} shutting down', array('worker' => $this));
        }else{
            $this->getProcess()->kill(SIGQUIT);
        }
    }
1285668
def stop_gracefully(self):
        '''

        '''
        if self.shutting_down:
            self.log(logging.INFO,
                     'second shutdown request, shutting down now')
            self.scram()
        else:
            self.log(logging.INFO, 'shutting down after current jobs finish')
            self.shutting_down = True
1345563
function() {
        // Important to configure later to not use UTC.
        later.date.localTime();

        // Shutdown on schedule.
        if (this.get('shutdownSchedule')) {
            this._shutdownSchedule = later.parse.cron(this.get('shutdownSchedule'));
            if (this._shutdownInterval) {
                this._shutdownInterval.clear();
            }

            this._shutdownInterval = later.setInterval(_.bind(function() {
                logger.info('App shutdown time has arrived. ' + new Date());
                this.set('restartCount', 0);
                this.shutdownApp();
            }, this), this._shutdownSchedule);
        }

        // Shutdown on schedule.
        if (this.get('shutdownPcSchedule')) {
            this._shutdownPcSchedule = later.parse.cron(this.get('shutdownPcSchedule'));
            if (this._shutdownPcInterval) {
                this._shutdownPcInterval.clear();
            }

            this._shutdownPcInterval = later.setInterval(_.bind(function() {
                logger.info('Machine shutdown time has arrived. ' + new Date());
                this.set('restartCount', 0);
                this.shutdownMachine();
            }, this), this._shutdownPcSchedule);
        }

        // Start up on schedule.
        if (this.get('startupSchedule')) {
            this._startupSchedule = later.parse.cron(this.get('startupSchedule'));
            if (this._startupInterval) {
                this._startupInterval.clear();
            }

            this._startupInterval = later.setInterval(_.bind(function() {
                logger.info('App startup time has arrived. ' + new Date());
                if (!$$serverState.get('runApp')) {
                    logger.info('Startup disabled by console.');
                    return;
                }

                this.set('restartCount', 0);
                this.startApp();
            }, this), this._startupSchedule);
        }

        // Start up on schedule.
        if (this.get('restartSchedule')) {
            this._restartSchedule = later.parse.cron(this.get('restartSchedule'));
            if (this._restartInterval) {
                this._restartInterval.clear();
            }

            this._restartInterval = later.setInterval(_.bind(function() {
                if (this._isStartingUp || this._isShuttingDown) {
                    return;
                }

                logger.info('App restart time has arrived. ' + new Date());
                if (!$$serverState.get('runApp')) {
                    logger.info('Startup disabled by console.');
                    return;
                }

                this.set('restartCount', 0);
                this.restartApp();
            }, this), this._restartSchedule);
        }

        // Restart machine on schedule.
        if (this.get('restartPcSchedule')) {
            this._restartPcSchedule = later.parse.cron(this.get('restartPcSchedule'));
            if (this._restartPcInterval) {
                this._restartPcInterval.clear();
            }

            this._restartPcInterval = later.setInterval(_.bind(function() {
                logger.info('Machine restart time has arrived. ' + new Date());

                this.restartMachine();

            }, this), this._restartPcSchedule);
        }

    }
687588
public void shutdown(boolean waitForJobsToComplete) {

        m_isShutdown = true;

        // signal each scheduler thread to shut down
        for (int i = 0; i < m_currentThreadCount; i++) {
            if (m_workers[i] != null) {
                m_workers[i].shutdown();
            }
        }

        // give waiting (wait(1000)) worker threads a chance to shut down
        // active worker threads will shut down after finishing their
        // current job
        synchronized (m_nextRunnableLock) {
            m_nextRunnableLock.notifyAll();
        }

        if (waitForJobsToComplete) {
            // wait until all worker threads are shut down
            int alive = m_currentThreadCount;
            while (alive > 0) {
                alive = 0;
                for (int i = 0; i < m_currentThreadCount; i++) {
                    if (m_workers[i].isAlive()) {
                        try {
                            if (LOG.isDebugEnabled()) {
                                LOG.debug(
                                    Messages.get().getBundle().key(Messages.LOG_THREAD_POOL_WAITING_1, new Integer(i)));
                            }

                            // note: with waiting infinite - join(0) - the application
                            // may appear to 'hang'
                            // waiting for a finite time however requires an additional loop (alive)
                            alive++;
                            m_workers[i].join(200);
                        } catch (InterruptedException e) {
                            // can be ignored
                        }
                    }
                }
            }

            int activeCount = m_threadGroup.activeCount();
            if ((activeCount > 0) && LOG.isInfoEnabled()) {
                LOG.info(
                    Messages.get().getBundle().key(Messages.LOG_THREAD_POOL_STILL_ACTIVE_1, new Integer(activeCount)));
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.get().getBundle().key(Messages.LOG_THREAD_POOL_SHUTDOWN_0));
            }
        }
    }
1327028
function closeAllWorkers() {
        Object.keys(cluster.workers).forEach(id => {

            // Get a handle on the worker process
            const worker = cluster.workers[id];

            // Check this worker isn't already done
            if (worker.state === "disconnected") {
                return;
            }

            // Tell the worker to shutdown
            worker.send("pluribus-shutdown");
            worker.disconnect();

            // If the worker is too slow, shut it down anyway
            const timeout = setTimeout(_ => {
                logger("Forcing", worker.process.pid, "to shutdown");
                worker.kill("SIGKILL");
            }, options.waitTimeout);

            // If the worker shuts down okay, cancel the forced shutdown
            worker.on("exit", function () {
                logger("Worker", worker.process.pid, "exited");
                clearTimeout(timeout);
            });
        });
    }
361920
def shutdown(self, wait=True):
    

    with self._lock:
      self._shutdown = True
      self._lock.notify_all()
    if wait:
      self.wait()
825892
@Override
  public void shutdown() {

    // delay a little bit in case an added job is still taking it's time getting started right
    // before shutdown is called.
    try {
      //      System.out.println("waiting...");
      Thread.sleep(100);
    } catch (Exception ignore) {
    }

    if (shuttingDown || closed) {
      return;
    }

    shuttingDown = true;

    logger.info("Scheduler shutting down...");

    standby();

    this.quartzSchedulerThread.halt();

    notifySchedulerListenersShuttingdown();

    // notify Jobs, so they can gracefully shutdown
    List<JobExecutionContext> jobs = getCurrentlyExecutingJobs();
    for (JobExecutionContext job : jobs) {
      if (job.getJobInstance() instanceof InterruptableJob) {
        try {
          ((InterruptableJob) job.getJobInstance()).interrupt();
        } catch (Throwable e) {
          // do nothing, this was just a courtesy effort
          logger.warn(
              "Encountered error when interrupting job {} during shutdown: {}",
              job.getJobDetail().getName(),
              e);
        }
      }
    }

    logger.info("Threadpool shutting down...");
    quartzSchedulerResources.getThreadPool().shutdown();

    // Scheduler thread may have be waiting for the fire time of an acquired
    // trigger and need time to release the trigger once halted, so make sure
    // the thread is dead before continuing to shutdown the job store.
    try {
      this.quartzSchedulerThread.join();
    } catch (InterruptedException ignore) {
    }

    closed = true;

    shutdownPlugins();

    notifySchedulerListenersShutdown();

    logger.info("Scheduler shutdown complete.");
  }
1140539
public function forceShutdown()
    {
        Event::fire(Event::WORKER_FORCE_SHUTDOWN, $this);

        if ($this->child === 0) {
            $this->log('Forcing shutdown of job <pop>'.$this->job.'</pop>', Logger::NOTICE);
        } else {
            $this->log('Forcing shutdown of worker <pop>'.$this.'</pop>', Logger::NOTICE);
        }

        $this->shutdown();
        $this->killChild();
    }
585912
def process(job = nil, &block)
      return unless job ||= reserve

      job.worker = self
      working_on job
      perform(job, &block)
    ensure
      done_working
    end
774451
async def on_shutdown(app):
    """"""
    global is_shutting_down
    is_shutting_down = True
    for task in app["websockets"]:
        task.cancel()
        try:
            await task
        except asyncio.CancelledError:
            pass
517190
function disconnectTimeoutHandler(worker, cluster) {
    verbose('worker %d is stuck in disconnect', worker.process.pid);

    // if this is not a suicide we need to preserve that as worker.kill() will make this a suicide
    if (!worker.suicide) {
      master.suicideOverrides[worker.id] = worker.id;
    }

    master.isRunning(worker, function(running) {
      if (!running) {
        return;
      }

      try {
        debug('sending SIGKILL to worker %d', worker.process.pid);
        process.kill(worker.process.pid, 'SIGKILL');
      } catch (e) {
        // this can happen.  don't crash!!
      }
    });
  }
149835
public void shutdown() {
        getLogger().info("removing receiverJob from the Scheduler.");

        if(this.repository instanceof LoggerRepositoryEx) {
          Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
          scheduler.delete(customReceiverJob);
        }

        lastID = -1;
    }
252670
protected final void awaitShutdown() throws InterruptedException {
		Runtime.getRuntime().addShutdownHook(new Thread(() -> {
			try {
				shutdown();
				finishLatch.await();
				Thread.sleep(10); // wait a bit for things outside `launch` call, such as JUnit finishing or whatever
			} catch (InterruptedException e) {
				logger.error("Shutdown took too long", e);
			}
		}, "shutdownNotification"));
		shutdownLatch.await();
	}
720756
public function shutdown()
    {
        if ($this->masterPid === posix_getpid() && !$this->finished) {
            // only master process.
            $this->dispatcher->dispatch(WorkerEvents::SHUTTING_DOWN, new WorkerShuttingDownEvent($this));
            $this->output->writeln("<info>Shutdown <comment>".$this->config->getName()."</comment>.</info>");
            $this->finished = true;
        }
    }
945601
public void shutdown() {
        shutdownCalled = true;
        if (isRunning()) {
            watchdog.waitForProcessStarted();
            watchdog.destroyProcess();
            watchdog.waitForTerminationAfterDestroy(2, SECONDS);
            if (isRunning()) {
                watchdog.destroyProcessForcefully();
                watchdog.waitForTerminationAfterDestroy(1, SECONDS);
                if (isRunning()) {
                    LOGGER.severe(String.format("Unable to kill process with PID %s", watchdog.getProcessId()));
                }
            }
        }

        // if shutdown() was called by something other than the shutdown hook, we don't need the shutdown hook anymore
        try {
            if (shutDownHook != null) {
                Runtime.getRuntime().removeShutdownHook(shutDownHook);
            }
        } catch (IllegalStateException e) {
            // ignore.. happens when the shutdown hook is in use, that's okay
        }

    }
1088782
public void shutdown() {
        if (_producer != null) {
            _producer.close();
        }
        _executorService.shutdown();
        try {
            if (!_executorService.awaitTermination(10, TimeUnit.SECONDS)) {
                _logger.warn("Shutdown of Kafka executor service timed out after 10 seconds.");
                _executorService.shutdownNow();
            }
        } catch (InterruptedException ex) {
            _logger.warn("Shutdown of executor service was interrupted.");
            Thread.currentThread().interrupt();
        }
    }
936536
def run(self):
        """"""
        executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
        loop = asyncio.get_event_loop()
        loop.run_until_complete(self._run_loop(executor))
        self._log.info('Shutting down...')
        executor.shutdown()