Stop backgroud thread and cleanup resources
517545
def cleanup(self):
        '''  '''
        self._processing_stop = True
        self._wakeup_processing_thread()
        self._processing_stopped_event.wait(3)
1311457
void stopReload() throws InterruptedException {
    if (reloadThread != null) {
      running = false;
      reloadThread.interrupt();
      reloadThread.join();
      reloadThread = null;
    }
  }
802840
def stop(self):
        
        with self.child_lock:
            children = copy(self.children)
        for c in children:
            DEBUG and c.name and Log.note("Stopping thread {{name|quote}}", name=c.name)
            c.stop()
        self.please_stop.go()

        DEBUG and Log.note("Thread {{name|quote}} got request to stop", name=self.name)
918273
@FFDCIgnore(IllegalStateException.class)
    private void removeShutdownHook() {
        if (shutdownHook != null) {
            try {
                Runtime.getRuntime().removeShutdownHook(shutdownHook);
            } catch (IllegalStateException e) {
                // do nothing.
            }
        }
    }
1013306
@Override
  public void stop() {
    threadPoolExecutor.shutdown();
    BlockingQueue<Runnable> taskQueue = threadPoolExecutor.getQueue();
    int bufferSizeBeforeShutdown = threadPoolExecutor.getQueue().size();
    boolean gracefulShutdown = true;
    try {
      gracefulShutdown = threadPoolExecutor.awaitTermination(shutdownTimeout, TimeUnit.SECONDS);
    }
    catch(InterruptedException e) {
      // we are anyways cleaning up
    }
    finally {
      int bufferSizeAfterShutdown = taskQueue.size();
      if(!gracefulShutdown || bufferSizeAfterShutdown > 0) {
        String errorMsg = "Kinesis Log4J Appender (" + name + ") waited for " + shutdownTimeout
                          + " seconds before terminating but could send only "
                          + (bufferSizeAfterShutdown - bufferSizeBeforeShutdown) + " logevents, it failed to send "
                          + bufferSizeAfterShutdown + " pending log events from it's processing queue";
        addError(errorMsg);
      }
    }
    client.shutdown();
  }
646288
public void purgeThreadLocal() {
        // if thread local pools exist, check to see if we have one created and
        // therefore need to tell it to purge
        if (null != threadLocals) {
            LocalThreadObjectPool pool = threadLocals.get();
            if (null != pool) {
                Object[] data = pool.purge();
                if (0 < data.length) {
                    mainPool.putBatch(data);
                }
            }
        }
    }
1142841
def stop(self):
        
        if self.server.eio.async_mode == 'threading':
            func = flask.request.environ.get('werkzeug.server.shutdown')
            if func:
                func()
            else:
                raise RuntimeError('Cannot stop unknown web server')
        elif self.server.eio.async_mode == 'eventlet':
            raise SystemExit
        elif self.server.eio.async_mode == 'gevent':
            self.wsgi_server.stop()
406660
def stop(self, timeout=None):
        
        ioloop = getattr(self, 'ioloop', None)
        if not ioloop:
            raise RuntimeError('Call start() before stop()')
        if timeout:
            if get_thread_ident() == self.ioloop_thread_id:
                raise RuntimeError('Cannot block inside ioloop')
            self._running.wait_with_ioloop(self.ioloop, timeout)

        def _cleanup():
            self._running.clear()
            self._disconnect()
        self._ioloop_manager.stop(timeout=timeout, callback=_cleanup)
899012
def stop(self):
        
        if self._process is None:
            return
        if self._shared:
            BackendManager.SHARE_COUNT -= 1
            if BackendManager.SHARE_COUNT:
                return
        comm('stopping backend process')
        # close all sockets
        for s in self._sockets:
            s._callback = None
            s.close()

        self._sockets[:] = []
        # prevent crash logs from being written if we are busy killing
        # the process
        self._process._prevent_logs = True
        while self._process.state() != self._process.NotRunning:
            self._process.waitForFinished(1)
            if sys.platform == 'win32':
                # Console applications on Windows that do not run an event
                # loop, or whose event loop does not handle the WM_CLOSE
                # message, can only be terminated by calling kill().
                self._process.kill()
            else:
                self._process.terminate()
        self._process._prevent_logs = False
        self._heartbeat_timer.stop()
        comm('backend process terminated')
1207789
public void stop() throws Exception {
        DruidIndices.getInstance().remove(String.valueOf(port));
        server.stop();
    }
1307238
def _fallback_cleanups(self):
        '''
        
        '''
        # Add an extra fallback in case a forked process leaks through
        multiprocessing.active_children()

        # Cleanup Windows threads
        if not salt.utils.platform.is_windows():
            return
        for thread in self.win_proc:
            if not thread.is_alive():
                thread.join()
                try:
                    self.win_proc.remove(thread)
                    del thread
                except (ValueError, NameError):
                    pass
1267857
public void stop() {
    Preconditions.checkState(running, "Cannot stop if it's not running");

    synchronized (this) {
      log.atInfo().log("stopping client background thread and flushing the report aggregator");
      for (ReportRequest req : reportAggregator.clear()) {
        try {
          transport.services().report(serviceName, req).execute();
        } catch (IOException e) {
          log.atSevere().withCause(e).log("direct send of a report request failed");
        }
      }
      this.stopped = true;  // the scheduler thread will set running to false
      if (isRunningSchedulerDirectly()) {
        resetIfStopped();
      }
      this.scheduler = null;
    }
  }
1154217
private void allowCleanShutdown() {
        DelayingShutdownHook hook = new DelayingShutdownHook();
        Context context = (Context) this.loggerFactory;
        hook.setContext(context);
        Thread hookThread = new Thread(hook, "Logback shutdown hook [" + context.getName() + "]");
        Runtime.getRuntime().addShutdownHook(hookThread);
    }
453968
private void stopResourceAdapter() {
        if (resourceAdapter != null)
            try {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(this, tc, "stop", resourceAdapter);
                ArrayList<ThreadContext> threadContext = startTask(raThreadContextDescriptor);
                try {
                    beginContext(raMetaData);
                    try {
                        ClassLoader previousClassLoader = jcasu.beginContextClassLoader(raClassLoader);
                        try {
                            resourceAdapter.stop();
                        } finally {
                            if (raClassLoader != null) {
                                jcasu.endContextClassLoader(raClassLoader, previousClassLoader);
                                classLoadingSvc.destroyThreadContextClassLoader(raClassLoader);
                            }
                        }
                    } finally {
                        endContext(raMetaData);
                    }
                } finally {
                    stopTask(raThreadContextDescriptor, threadContext);
                }

                // Cancel timers
                for (Timer timer = timers.poll(); timer != null; timer = timers.poll()) {
                    timer.cancel();
                    timer.purge();
                }

                // Cancel/release work
                workManager.stop();
            } catch (Throwable x) {
                // auto FFDC
            } finally {
                // decrement the reference count
                BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
                if (bundleContext != null) {
                    bundleContext.ungetService(contextSvcRef);
                }
            }
    }
389517
def remove_stopped_threads (self):
        """"""
        self.threads = [t for t in self.threads if t.is_alive()]
1051055
def cleanup_sweep_threads():
    '''
    
    '''

    for dict_name, obj in globals().items():
        if isinstance(obj, (TimedDict,)):
            logging.info(
                'Stopping thread for TimedDict {dict_name}'.format(
                    dict_name=dict_name))
            obj.stop_sweep()
813438
def stop_sync(self):
        """"""

        if self._control_thread is not None and self._control_thread.is_alive():
            self._control_thread.stop()
            self._control_thread.join()

        if self.jlink is not None:
            self.jlink.close()