(internal) Intended to be run in a seperate thread. Feeds tasks into 
        to the pool whenever semaphore permits. Finishes if self._stopping is 
        set.
436633
def _pool_put(pool_semaphore, tasks, put_to_pool_in, pool_size, id_self, \
                  is_stopping):
        
        log.debug('NuMap(%s) started pool_putter.' % id_self)
        last_tasks = {}
        for task in xrange(tasks.lenght):
            last_tasks[task] = -1
        stop_tasks = []
        while True:
            # are we stopping the Weaver?
            if is_stopping():
                log.debug('NuMap(%s) pool_putter has been told to stop.' % \
                           id_self)
                tasks.stop()
            # try to get a task
            try:
                log.debug('NuMap(%s) pool_putter waits for next task.' % \
                           id_self)
                task = tasks.next()
                log.debug('NuMap(%s) pool_putter received next task.' % id_self)
            except StopIteration:
                # Weaver raised a StopIteration
                stop_task = tasks.i # current task
                log.debug('NuMap(%s) pool_putter caught StopIteration from task %s.' % \
                                                                  (id_self, stop_task))
                if stop_task not in stop_tasks:
                    # task raised stop for the first time.
                    log.debug('NuMap(%s) pool_putter task %s first-time finished.' % \
                                                           (id_self, stop_task))
                    stop_tasks.append(stop_task)
                    pool_semaphore.acquire()
                    log.debug('NuMap(%s) pool_putter sends a sentinel for task %s.' % \
                                                           (id_self, stop_task))
                    put_to_pool_in((stop_task, None, last_tasks[stop_task]))
                if len(stop_tasks) == tasks.lenght:
                    log.debug('NuMap(%s) pool_putter sent sentinels for all tasks.' % \
                                                                        id_self)
                    # all tasks have been stopped
                    for _worker in xrange(pool_size):
                        put_to_pool_in(None)
                    log.debug('NuMap(%s) pool_putter sent sentinel for %s workers' % \
                                                           (id_self, pool_size))
                    # this kills the pool_putter
                    break
                # multiple StopIterations for a tasks are ignored. 
                # This is for stride.
                continue

            # got task
            last_tasks[tasks.i] = task[-1][0] # last valid result
            log.debug('NuMap(%s) pool_putter waits for semaphore for task %s' % \
                       (id_self, task))
            pool_semaphore.acquire()
            log.debug('NuMap(%s) pool_putter gets semaphore for task %s' % \
                       (id_self, task))
            #gc.disable()
            put_to_pool_in(task)
            #gc.enable()
            log.debug('NuMap(%s) pool_putter submits task %s to worker.' % \
                       (id_self, task))
        log.debug('NuMap(%s) pool_putter returns' % id_self)
1130113
@Override
  public void stop() {
    LOGGER.debug("Shutting down PooledExecutionService");
    running = false;
    scheduledExecutor.shutdownNow();
    for (Iterator<Entry<String, ThreadPoolExecutor>> it = pools.entrySet().iterator(); it.hasNext(); ) {
      Entry<String, ThreadPoolExecutor> e = it.next();
      try {
        destroyPool(e.getKey(), e.getValue());
      } finally {
        it.remove();
      }
    }
    try {
      while(!scheduledExecutor.awaitTermination(30, SECONDS)) {
        LOGGER.warn("Timeout while waiting on scheduler to finish, keep waiting");
      }
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
384734
public boolean stop() {
        if (!this.isTailing.get()) {
            LogWatchTailingManager.LOGGER.debug("Tailer not running, therefore not terminating.");
            return false;
        }
        /*
         * terminate tailer; we stop the scheduler and the task will therefore
         * never be started again
         */
        this.tailer.stop();
        LogWatchTailingManager.LOGGER.info("Terminated tailing #{} for {}.",
                this.numberOfTimesThatTailerWasStarted.get(), this.watch);
        return true;
    }
1339268
def suspend_all(self):
        
        pool = Pool(concurrency=3)
        for node in self.nodes.values():
            pool.append(node.suspend)
        yield from pool.join()
452881
def stop(self):
        
        self._running = False
        if self._self_thread is not None:
            self._self_thread.cancel()
            self._self_thread = None
11828
def _run(self):
        ''''''
      
        while self._is_running:
            yield from self._task()

        # Signal that the loop has finished.
        self._run_complete.set_result(True)
88372
def start
      @stop_mutex.synchronize do
        fail 'already stopped' if @stopped
      end
      until @workers.size == @size.to_i
        new_worker_queue = Queue.new
        @ready_workers << new_worker_queue
        next_thread = Thread.new(new_worker_queue) do |jobs|
          catch(:exit) do  # allows { throw :exit } to kill a thread
            loop_execute_jobs(jobs)
          end
          remove_current_thread
        end
        @workers << next_thread
      end
    end
273105
def join(self, timeout=None):
        
        if self._context.state == RUNNING:
            raise RuntimeError('The Pool is still running')
        if self._context.state == CLOSED:
            self._wait_queue_depletion(timeout)
            self.stop()
            self.join()
        else:
            self._context.task_queue.put(None)
            self._stop_pool()
1239659
def run(self, loop=None):
        
        if loop is None:
            loop = asyncio.get_event_loop()

        self.loop = loop

        loop.run_until_complete(self.startup())

        for func in self.tasks:
            self.start_task(func)

        try:
            task = self.start_task(self.main_task)
            loop.run_until_complete(task)
        except (KeyboardInterrupt, SystemError):
            print("Attempting graceful shutdown, press Ctrl-C again to exit", flush=True)

            def shutdown_exception_handler(_loop, context):
                if "exception" not in context or not isinstance(context["exception"], asyncio.CancelledError):
                    _loop.default_exception_handler(context)
            loop.set_exception_handler(shutdown_exception_handler)

            tasks = asyncio.gather(*self._started_tasks, loop=loop, return_exceptions=True)
            tasks.add_done_callback(lambda _: loop.stop())
            tasks.cancel()

            while not tasks.done() and not loop.is_closed():
                loop.run_forever()
        finally:
            loop.run_until_complete(self.shutdown())
            loop.run_until_complete(self.cleanup())
            loop.close()
46392
def start(self):
        
        if not self._done_event.is_set():
            # Stop event not set: we're running
            return

        # Clear the stop event
        self._done_event.clear()

        # Compute the number of threads to start to handle pending tasks
        nb_pending_tasks = self._queue.qsize()
        if nb_pending_tasks > self._max_threads:
            nb_threads = self._max_threads
            nb_pending_tasks = self._max_threads
        elif nb_pending_tasks < self._min_threads:
            nb_threads = self._min_threads
        else:
            nb_threads = nb_pending_tasks

        # Create the threads
        for _ in range(nb_pending_tasks):
            self.__nb_pending_task += 1
            self.__start_thread()
        for _ in range(nb_threads - nb_pending_tasks):
            self.__start_thread()
186645
public void run() {
//    todo    if (logger.isDebugEnabled()) {
//            logger.debug("start running PooledDataSourceCleaner");
//        }

        state = STATE_CLEANER.RUNNING;
        while (state != STATE_CLEANER.SHUTDOWN) {
            try {
                Thread.sleep(interval * 1000);
            } catch (InterruptedException e) {
//              todo  if (logger.isDebugEnabled()) {
//                    logger.debug("Get interrupted, shutdown the PooledDataSourceCleaner");
//                }
                break;//get out if anyone interrupt
            }
            this.manager.cleanDataSources();

            //if no pool at all, going to stop itself
            if (this.manager.getDbmsPoolSize() == 0) {
//             todo   if (logger.isDebugEnabled()) {
//                    logger.debug("Empty pools, shutdown the PooledDataSourceCleaner");
//                }
                state = STATE_CLEANER.SHUTDOWN;//stop spinning
                break; //get out
            }
        }
    }
630500
@Write(consumes = {})
    public Object stop() {
        try {
            return message;
        } finally {
            Thread thread = new Thread(this::stopServer);
            thread.setContextClassLoader(getClass().getClassLoader());
            thread.start();
        }
    }
579435
def Stop(self, join_timeout=600):
    """"""
    if not self.started:
      logging.warning("Tried to stop a thread pool that was not running.")
      return

    # Remove all workers from the pool.
    workers = list(itervalues(self._workers))
    self._workers = {}
    self._workers_ro_copy = {}

    # Send a stop message to all the workers. We need to be careful here to not
    # send messages while we are still counting. If threads that haven't been
    # counted yet pick up a message and exit, the count will be off and the
    # shutdown process will deadlock.
    stop_messages_needed = 0
    for worker in workers:
      if worker.isAlive():
        stop_messages_needed += 1

    for _ in range(stop_messages_needed):
      self._queue.put(STOP_MESSAGE)

    self.started = False
    self.Join()

    # Wait for the threads to all exit now.
    for worker in workers:
      worker.join(join_timeout)
      if worker.isAlive():
        raise RuntimeError("Threadpool worker did not finish in time.")
397708
def task_finished(self, watchdog):
		
		if watchdog in self.__running_registry:  # when cleanup hits stop
			self.__running_registry.remove(watchdog)
			self.__done_registry.append(watchdog)
			self.cleanup_event().set()
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
152750
public synchronized void stop() {
        Thread tmp=runner;
        runner=null;
        if(tmp != null) {
            tmp.interrupt();
            try {tmp.join(500);} catch(InterruptedException e) {}
        }

        // we may need to do multiple iterations as the iterator works on a copy and tasks might have been added just
        // after the iterator() call returned
        while(!queue.isEmpty())
            for(Task entry: queue) {
                entry.cancel(true);
                queue.remove(entry);
            }
        queue.clear();

        if(pool instanceof ThreadPoolExecutor && shut_down_pool) {
            ThreadPoolExecutor p=(ThreadPoolExecutor)pool;
            List<Runnable> remaining_tasks=p.shutdownNow();
            remaining_tasks.stream().filter(task -> task instanceof Future).forEach(task -> ((Future)task).cancel(true));
            p.getQueue().clear();
            try {
                p.awaitTermination(Global.THREADPOOL_SHUTDOWN_WAIT_TIME, TimeUnit.MILLISECONDS);
            }
            catch(InterruptedException e) {
            }
        }

        // clears the threads list (https://issues.jboss.org/browse/JGRP-1971)
        if(timer_thread_factory instanceof LazyThreadFactory)
            ((LazyThreadFactory)timer_thread_factory).destroy();
    }
819218
public synchronized void stop() {
		// Mark us closed
		stopped = true;
		try {
			// Kick the server accept loop
			serverSocket.close();

			// acquire all semaphores so that we wait for all connections to finish before we report back as closed
			semaphore.acquireUninterruptibly(MAXIMUM_CONCURRENT_READERS);
		} catch (IOException e) {
			log.log(Level.SEVERE, "Caught exception: ", e);
		}
	}