Terminate the agent, clean the files, close connections
        Should be called manually
12068
def close(self):
        
        os.remove(self._file)
        os.rmdir(self._dir)
        self.thread._exit = True
        self.thread.join(1000)
        self._close()
549164
def exit(self):
        """"""
        # To ensure all connections are properly closed
        self.client.flush()
        self.client.close()
        # Call the father method
        super(Export, self).exit()
195168
@Override
    synchronized public void cleanup() {
        LOGGER.info("Cleanup the DirectorySocket.");

        if(task != null){
            task.toStop();
            task = null;
        }

        if(client != null){
            try {
                client.stop();
            } catch (Exception e) {
                LOGGER.warn("Close WebSocketClient get exception.", e);
            }
            client = null;
        }

        try {
            if(session != null){
                session.close();
            }
        } catch (IOException e) {
            LOGGER.warn("Close the WebSocket Session get exception.", e);
        }

        if(sessionFuture != null){
            try {
            sessionFuture.cancel(true);
            } catch (Exception e) {
                // do nothing
            }
        }

        session = null;
        sessionFuture = null;
        websocketStarted = false;
        connected = false;
        isStarted = false;
    }
998386
private function cleanupSlaveConnections()
    {
        foreach ($this->config['database']['connections'] as $name => $connection) {
            if (count($connection['slaves']) <= 0) {
                unset($this->config['database']['connections'][$name]['slaves']);
            }
        }
    }
1040543
private function closeAndAttemptToCleanupAllFiles()
    {
        // close the writer, which should remove all temp files
        $this->close();

        // remove output file if it was created
        if ($this->globalFunctionsHelper->file_exists($this->outputFilePath)) {
            $outputFolderPath = dirname($this->outputFilePath);
            $fileSystemHelper = new FileSystemHelper($outputFolderPath);
            $fileSystemHelper->deleteFile($this->outputFilePath);
        }
    }
573477
def cleanup(self):
        
        now = time.time()
        expired = now - NODE_TIMEOUT
        if self.conn.zremrangebyscore(self.key, 0, expired):
            self._notify()
255773
def _cleanup(self) -> None:
        """"""
        if self._cleanup_handle:
            self._cleanup_handle.cancel()

        now = self._loop.time()
        timeout = self._keepalive_timeout

        if self._conns:
            connections = {}
            deadline = now - timeout
            for key, conns in self._conns.items():
                alive = []
                for proto, use_time in conns:
                    if proto.is_connected():
                        if use_time - deadline < 0:
                            transport = proto.transport
                            proto.close()
                            if (key.is_ssl and
                                    not self._cleanup_closed_disabled):
                                self._cleanup_closed_transports.append(
                                    transport)
                        else:
                            alive.append((proto, use_time))

                if alive:
                    connections[key] = alive

            self._conns = connections

        if self._conns:
            self._cleanup_handle = helpers.weakref_handle(
                self, '_cleanup', timeout, self._loop)
278018
function cleanUp() {
    if (done) return
    done = true

    wsConn.removeListener("message", onMessage)
    wsConn.removeListener("close",   onClose)
    wsConn.removeListener("error",   onError)
  }
843280
def cleanup(self):
        """"""
        try:
            self.exit_config_mode()
        except Exception:
            # Always try to send 'exit' regardless of whether exit_config_mode works or not.
            pass
        self._session_log_fin = True
        self.write_channel("exit" + self.RETURN)
959605
def cleanup(self):
        

        # if an event broker has been created for this service
        if self.event_broker:
            # stop the event broker
            self.event_broker.stop()
        # attempt
        try:
            # close the http server
            self._server_handler.close()
            self.loop.run_until_complete(self._server_handler.wait_closed())
            self.loop.run_until_complete(self._http_handler.finish_connections(shutdown_timeout))

        # if there was no handler
        except AttributeError:
            # keep going
            pass

        # more cleanup
        self.loop.run_until_complete(self.app.shutdown())
        self.loop.run_until_complete(self.app.cleanup())
1030220
def Cleanup(self):
		
		self.lock.acquire()
		try:
			for bucket in self.connections.values():
				try:
					for conn in bucket:
						conn.lock()
						try:
							open = conn.TestConnection(forceCheck=True)
							if open is True:
								conn.commit()
							else:
								#Remove the connection from the pool. Its dead better of recreating it.
								index = bucket.index(conn)
								del bucket[index]
							conn.release()
						except Exception:
							conn.release()
				except Exception:
					pass
		finally:
			self.lock.release()
910152
def _cleanupConnections(senderkey, signal):
    """"""
    try:
        receivers = connections[senderkey][signal]
    except:
        pass
    else:
        if not receivers:
            # No more connected receivers. Therefore, remove the signal.
            try:
                signals = connections[senderkey]
            except KeyError:
                pass
            else:
                del signals[signal]
                if not signals:
                    # No more signal connections. Therefore, remove the sender.
                    _removeSender(senderkey)
613551
def cleanup(self):
        
        for future in self.futures:
            future.cancel()
        self.executor.shutdown(wait=10)
        if self.ssh.get_transport() != None:
            self.ssh.close()
845856
def terminate(self):
        
        rs = self.connection.terminate_instances([self.id])
        if len(rs) > 0:
            self._update(rs[0])
932806
private void internalCleanup()
    {
        if(hasBroker())
        {
            PersistenceBroker broker = getBroker();
            if(log.isDebugEnabled())
            {
                log.debug("Do internal cleanup and close the internal used connection without" +
                        " closing the used broker");
            }
            ConnectionManagerIF cm = broker.serviceConnectionManager();
            if(cm.isInLocalTransaction())
            {
                /*
                arminw:
                in managed environment this call will be ignored because, the JTA transaction
                manager control the connection status. But to make connectionManager happy we
                have to complete the "local tx" of the connectionManager before release the
                connection
                */
                cm.localCommit();
            }
            cm.releaseConnection();
        }
    }
715423
def close(self):
        """"""

        if hasattr(self, "conn"):
            self.conn.close()
            del self.conn
        if hasattr(self, "user"):
            del self.user
702743
function close() {
  log.notice('removing the unix socket file')
  try {
    fs.unlinkSync(file);
  }catch(e){} // nothing to do at this point

  Server.prototype.close.call(this);
}