Tell num_workers worker threads to quit after their current task.
177546
def dismissWorkers(self, num_workers):
        """"""
        for i in range(min(num_workers, len(self.workers))):
            worker = self.workers.pop()
            worker.dismiss()
1231036
def _stop(self):
        
        if self._started.isSet():
            # join threads
            self._pool_getter.join()
            self._pool_putter.join()
            for worker in self.pool:
                worker.join()
            # remove threads  
            del self._pool_putter
            del self._pool_getter
            del self.pool
            # remove results
            self._tasks = []
            self._tasks_tracked = {}
            # virgin variables
            self._stopping.clear()
            self._started.clear()
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);
            });
        });
    }
423415
private function waitForAllToFinish(): void
    {
        do {
            foreach ($this->workers as $key => $worker) {
                if (!$worker->isRunning()) {
                    unset($this->workers[$key]);
                }
            }
            usleep(10000);
            $this->printOutput();
        } while (\count($this->workers) > 0);
    }
733242
def worker_exec(self, **kwargs):
        """"""
        self.feed(**kwargs)
        self.logger.info('thread {} exit'.format(current_thread().name))
218774
def stop(self):
        """"""
        self.threads = {}
        self.new_threads = {}
        self.answer = ""
        self.ask_lock = False
904252
def stop_worker(config, *, worker_ids=None):
    
    if worker_ids is not None and not isinstance(worker_ids, list):
        worker_ids = [worker_ids]

    celery_app = create_app(config)
    celery_app.control.shutdown(destination=worker_ids)
416699
def reap_workers(waitpidflags = 0)
      loop do
        worker_pid, status = Process.waitpid2(-1, waitpidflags)
        if worker_pid.nil?
          return :none_ready
        else
          log "Worker exited #{status}"
          finish_worker(worker_pid, status)
          report_to_master("-#{worker_pid}")
        end
      end
    rescue Errno::ECHILD
      # All done
      :no_child
    end
1013818
def quit(self):
        
        def q(*args):
            raise urwid.ExitMainLoop()
        self.worker.shutdown(wait=False)
        self.ui_worker.shutdown(wait=False)
        self.loop.set_alarm_in(0, q)
157532
void stopNow() {
        assert currentThread() != this : "stopNow must not be called on the migration thread";
        running = false;
        queue.clear();
        interrupt();
        boolean currentThreadInterrupted = false;
        while (true) {
            try {
                join();
            } catch (InterruptedException e) {
                currentThreadInterrupted = true;
                continue;
            }
            break;
        }
        if (currentThreadInterrupted) {
            currentThread().interrupt();
        }
    }
1359634
async def cancel(self):
        """"""
        self.is_cancelled = True
        if self.future is not None:
            self.future.cancel()
        if self.task_process is not None:
            log.warning("Worker is shutting down, but a task is running. Terminating task")
            await self.task_process.worker_shutdown_stop()
748402
def start(self):
        """"""
        if self.working:
            return
        self.working = True
        for i in range(self.num_workers):
            w = threading.Thread(
                name="Worker Thread #{i}".format(i=i),
                target=self._worker,
                )
            w.daemon = True
            w.start()
            self.workers.append(w)
893941
def stop(self, timeout=5):
        
        # Must shut down threads here so the code that calls
        # this method can know when all threads are stopped.
        for worker in self._threads:
            self._queue.put(_SHUTDOWNREQUEST)

        # Don't join currentThread (when stop is called inside a request).
        current = threading.currentThread()
        if timeout is not None and timeout >= 0:
            endtime = time.time() + timeout
        while self._threads:
            worker = self._threads.pop()
            if worker is not current and worker.isAlive():
                try:
                    if timeout is None or timeout < 0:
                        worker.join()
                    else:
                        remaining_time = endtime - time.time()
                        if remaining_time > 0:
                            worker.join(remaining_time)
                        if worker.isAlive():
                            # We exhausted the timeout.
                            # Forcibly shut down the socket.
                            c = worker.conn
                            if c and not c.rfile.closed:
                                try:
                                    c.socket.shutdown(socket.SHUT_RD)
                                except TypeError:
                                    # pyOpenSSL sockets don't take an arg
                                    c.socket.shutdown()
                            worker.join()
                except (
                    AssertionError,
                    # Ignore repeated Ctrl-C.
                    # See
                    # https://github.com/cherrypy/cherrypy/issues/691.
                    KeyboardInterrupt,
                ):
                    pass
1298614
def stop(self):
        """"""
        with self._lock_c:
            for task in self.taskset:
                try:
                    task.stop()

                except TaskError as e:
                    # Task does not have a way to stop it.
                    # TODO: notify who?
                    pass
1154268
def stop(self):
        
        if self._io_thread is not None:
            self.log.info("Waiting for I/O thread to stop...")
            self.closed = True
            self._io_thread.join()

        if self._writer_thread is not None:
            self.log.info("Waiting for Writer Thread to stop...")
            self.closed = True
            self._writer_thread.join()

        self.log.info("All worker threads stopped.")
389517
def remove_stopped_threads (self):
        """"""
        self.threads = [t for t in self.threads if t.is_alive()]
1192778
def terminate(self):
        """"""
        self.close()

        # Clearing the job queue
        try:
            while 1:
                self._workq.get_nowait()
        except queue.Empty:
            pass

        # Send one sentinel for each worker thread: each thread will die
        # eventually, leaving the next sentinel for the next thread
        for _ in self._workers:
            self._workq.put(SENTINEL)