Start a new thread to shutdown the server
186588
private void stopServer() {
        // Get current server
        final Server targetServer = this.getServer();

        // Start a new thread in order to escape the destruction of this Handler
        // during the stop process.
        new Thread() {
            @Override
            public void run() {
                try {
                    targetServer.stop();
                } catch (Exception e) {
                    // ignore
                }
            }
        }.start();

    }
264747
def shutdown_server(self):
        """"""
        self.log.debug('shutdown_server: in')
        if self.ensime and self.toggle_teardown:
            self.ensime.stop()
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();
	}
149181
@Override
  public void run() {
    long startTime = System.currentTimeMillis();
    
    try {
      LOG.info("Starting the history thread ...");
      while (!core.shutdownPending()) {
        checkRampUp(startTime);
        cleanUpHistory();
        Thread.sleep(loopSleepTime);
      }
      LOG.info("History thread shutdown.");
    } catch (Exception e) {
      LOG.error("ServerHistory died", e);
    } finally {
      core.shutdown();
    }
  }
1260624
def start(self):
        
        if self._started:
            raise RuntimeError("thread already started")

        def run():
            try:
                self.run(*self._args, **self._kwargs)
            except SystemExit:
                # only shut down the thread, not the whole process
                pass
            finally:
                self._deactivate()

        self._glet = scheduler.greenlet(run)
        self._ident = id(self._glet)
        scheduler.schedule(self._glet)
        self._activate()
202618
def server_off(self):
        '''  '''
        if (self.server.is_server_running() == 'yes' or
                self.server.is_server_running() == 'maybe'):
            self.server.shutdown()
            print 'Please wait. This could take a few seconds.'
            time.sleep(0.5)
71945
@Override
    public void shutdown() {
        final WireMockServer server = this;
        Thread shutdownThread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    // We have to sleep briefly to finish serving the shutdown request before stopping the server, as
                    // there's no support in Jetty for shutting down after the current request.
                    // See http://stackoverflow.com/questions/4650713
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                server.stop();
            }
        });
        shutdownThread.start();
    }
1334094
public void shutdown() {
        debugConnection = null;
        shuttingDown = true;
        try {
            if (serverSocket != null) {
                serverSocket.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
937179
def shutdown_mp(self, clean=True):
        
        # The server runs on a worker thread, so we need to shut it down first.
        if hasattr(self, 'server'):
            # Shutdown the server quickly.
            try:
                # For some strange reason, this throws an OSError on windows.
                self.server.socket.shutdown(socket.SHUT_RDWR)
            except OSError:
                pass
            self.server.socket.close()
            self.server.shutdown()
        if hasattr(self, 'handler'):
            self.handler.workers.stop_workers(clean)
732434
public void shutdown() throws Throwable
   {
      HandlerServer handlerServer = handlerServers.remove(getKey());

      if (handlerServer != null)
         handlerServer.stop();
   }
717838
function addShutdown(server) {
  var connections = {};
  var isShuttingDown = false;
  var connectionCounter = 0;

  function destroy(socket, force) {
    if (force || (socket._isIdle && isShuttingDown)) {
      socket.destroy();
      delete connections[socket._connectionId];
    }
  };

  function onConnection(socket) {
    var id = connectionCounter++;
    socket._isIdle = true;
    socket._connectionId = id;
    connections[id] = socket;

    socket.on('close', function() {
      delete connections[id];
    });
  };

  server.on('request', function(req, res) {
    req.socket._isIdle = false;

    res.on('finish', function() {
      req.socket._isIdle = true;
      destroy(req.socket);
    });
  });

  server.on('connection', onConnection);
  server.on('secureConnection', onConnection);

  function shutdown(force, cb) {
    isShuttingDown = true;
    server.close(function(err) {
      if (cb) {
        process.nextTick(function() { cb(err); });
      }
    });

    Object.keys(connections).forEach(function(key) {
      destroy(connections[key], force);
    });
  };

  server.shutdown = function(cb) {
    shutdown(false, cb);
  };

  server.forceShutdown = function(cb) {
    shutdown(true, cb);
  };

  return server;
}
601546
def start(self, join=False):
        
        Thread.start(self)

        if join:
            try:
                while self.is_alive():
                    self.join(timeout=60)
                self.logger.info("worker {0} exit unexpected, try to shutdown it".format(self.option.consumer_name))
                self.shutdown()
            except KeyboardInterrupt:
                self.logger.info("*** try to exit **** ")
                self.shutdown()
782015
def shutdown(host=None, port=None, db=None, password=None):
    '''
    
    '''
    server = _connect(host, port, db, password)
    try:
        # Return false if unable to ping server
        server.ping()
    except redis.ConnectionError:
        return False

    server.shutdown()
    try:
        # This should fail now if the server is shutdown, which we want
        server.ping()
    except redis.ConnectionError:
        return True
    return False
699664
def stop(self):
        
        if self.is_run:
            self._service.shutdown()
            self._service.server_close()
83288
public synchronized void stop() {

        if (m_thread != null) {
            long timeBeforeShutdownWasCalled = System.currentTimeMillis();
            JLANServer.shutdownServer(new String[] {});
            while (m_thread.isAlive()
                && ((System.currentTimeMillis() - timeBeforeShutdownWasCalled) < MAX_SHUTDOWN_WAIT_MILLIS)) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // ignore
                }
            }
        }

    }
483612
public void shutdownNow() throws Exception {
    this.server.stop();
    this.server.destroy();
    getFlowRunnerManager().shutdownNow();
    this.mbeanRegistrationManager.closeMBeans();
  }
1109768
public void stop() throws IOException {
		synchronized (this.monitor) {
			if (this.listenThread != null) {
				closeAllConnections();
				try {
					this.executor.shutdown();
					this.executor.awaitTermination(1, TimeUnit.MINUTES);
				}
				catch (InterruptedException ex) {
					Thread.currentThread().interrupt();
				}
				this.serverSocket.close();
				try {
					this.listenThread.join();
				}
				catch (InterruptedException ex) {
					Thread.currentThread().interrupt();
				}
				this.listenThread = null;
				this.serverSocket = null;
			}
		}
	}