Check if the server is alive.

        :param reconnect: If the connection is closed, reconnect.
        :raise Error: If the connection is closed and reconnect=False.
358842
def ping(self, reconnect=True):
        
        if self._sock is None:
            if reconnect:
                self.connect()
                reconnect = False
            else:
                raise err.Error("Already closed")
        try:
            self._execute_command(COMMAND.COM_PING, "")
            self._read_ok_packet()
        except Exception:
            if reconnect:
                self.connect()
                self.ping(False)
            else:
                raise
586072
def _try_reconnect(self):
        """"""

        try:
            if self.connection_interrupted:
                self.connect_direct(self.connection_string, force=True)
                self.connection_interrupted = False
                self.connected = True

                # Reenable streaming interface if that was open before as well
                if self._reports is not None:
                    self._loop.run_coroutine(self.adapter.open_interface(0, 'streaming'))

                # Reenable tracing interface if that was open before as well
                if self._traces is not None:
                    self._loop.run_coroutine(self.adapter.open_interface(0, 'tracing'))
        except HardwareError as exc:
            self._logger.exception("Error reconnecting to device after an unexpected disconnect")
            raise HardwareError("Device disconnected unexpectedly and we could not reconnect", reconnect_error=exc) from exc
397488
def _reconnect(self):
        
        if self.idle or self.closed:
            LOGGER.debug('Attempting RabbitMQ reconnect in %s seconds',
                         self.reconnect_delay)
            self.io_loop.call_later(self.reconnect_delay, self.connect)
            return
        LOGGER.warning('Reconnect called while %s', self.state_description)
1281979
def _reconnect(self, errorState):
        
        def connect():
            if self.noisy:
                log.msg("Reconnecting now.")
            self.connect()

        backOff = self.backOffs[errorState]

        if self._errorState != errorState or self._delay is None:
            self._errorState = errorState
            self._delay = backOff['initial']
        else:
            self._delay = min(backOff['max'], self._delay * backOff['factor'])

        if self._delay == 0:
            connect()
        else:
            self._reconnectDelayedCall = self.reactor.callLater(self._delay,
                                                                connect)
            self._toState('waiting')
1170285
def is_alive(self):
        
        if self.__send_ready.is_set() and self.__recv_ready.is_set():
            if self.__send_thread is not None and self.__recv_thread is not None:
                return self.__send_thread.is_alive() and self.__recv_thread.is_alive()
        return False
351727
def open(self):
        
        try:
            if self.conn.get_backend_pid():
                return True
        except psycopg2.InterfaceError as e:
            if str(e) == "connection already closed":
                # We already lost our connection. Attempt to reforge it.
                self.__reconnect__()
                if self.conn.get_backend_pid() >= 0:
                    return True # Resets it.
            else:
                raise e
427589
def __on_connect(self, client, userdata, flags, result_code):
        # pylint: disable=W0613
        
        if result_code:
            # result_code != 0: something wrong happened
            _logger.error(
                "Error connecting the MQTT server: %s (%d)",
                paho.connack_string(result_code),
                result_code,
            )
        else:
            # Connection is OK: stop the reconnection timer
            self.__stop_timer()

        # Notify the caller, if any
        if self.on_connect is not None:
            try:
                self.on_connect(self, result_code)
            except Exception as ex:
                _logger.exception("Error notifying MQTT listener: %s", ex)
959336
def disconnect(self):
        
        if self._state == _State.CONNECTED:
            self._state = _State.DISCONNECTING
            self._transport.loseConnection()
            return self._notify_on_disconnect()
        if self._state == _State.CONNECTING:
            return fail(ClientConnecting())
        elif self._state == _State.NOT_CONNECTED:
            return succeed(None)
        elif self._state == _State.DISCONNECTING:
            return self._notify_on_disconnect()
1094483
def reconnect(self):
        """"""
        try:
            self.conn.close()
        except Exception,e:
            self.logger.warn(e)

        self.createConnection()

        return True
479215
protected function checkConnection($reconnect = false)
        {
            if(empty($this->_lnk)) {
                $this->log('CheckConnection: link is not valid');
                if($reconnect) {
                    $this->log('CheckConnection: try to reconnect');
                    $this->_lnk = @odbc_connect('Driver=' . VERTICA_DRIVER . ';Servername=' . VERTICA_SERVER . ';Database='.VERTICA_DATABASE, VERTICA_USER_ETL, VERTICA_PASS_ETL);
                    if(!$this->_lnk) {
                        $this->log('CheckConnection: reconnect failed');
                        throw new Exception('Connection failed or gone away and can\'t reconnect - '.odbc_errormsg($this->_link), self::CONNECTION_FAILED);
                    }
                    $this->log('CheckConnection: reconnected!');
                    return;
                }
                throw new Exception('Connection failed or gone away - ' . odbc_errormsg($this->_link), self::CONNECTION_FAILED);
            }
        }
1096166
def reconnect
      tries = 0
      begin
        redis.synchronize do |client|
          client.reconnect
        end
      rescue Redis::BaseConnectionError
        if (tries += 1) <= 3
          log "Error reconnecting to Redis; retrying"
          sleep(tries)
          retry
        else
          log "Error reconnecting to Redis; quitting"
          raise
        end
      end
    end
459908
def reconnect(self, conn_retries=None):
        '''  '''
        if conn_retries is None:
            conn_retries = self.conn_retries

        count = 0
        if self.logger:
            self.logger.info('Connecting to Redis..')
        while count < conn_retries:
            super(redis.client.Redis, self).__init__(*self.args, **self.kwargs)

            if self.ping():
                if self.logger:
                    self.logger.info('Connected to Redis!')
                return True
            else:
                sl = min(3 ** count, self.max_sleep)
                if self.logger:
                    self.logger.info('Connecting failed, retrying in {0} seconds'.format(sl))
                time.sleep(sl)
                count += 1
        raise ConnectionError
1226041
def reconnect(self):
        
        self.connect(*self._saved_connect.args, **self._saved_connect.kwargs)
469682
def connectionLost(self, reason=protocol.connectionDone):
        
        self.connected = 0

        for pending in self._queue.values():
            pending.errback(reason)
        self._queue.clear()

        if self._stopped:
            result = self if reason.check(error.ConnectionDone) else reason
            self._stopped.callback(result)
            self._stopped = None
        else:
            reason.raiseException()
1050647
async def reconnect(self):
        
        monitor = self.monitor
        if monitor.reconnecting.locked() or monitor.close_called.is_set():
            return
        async with monitor.reconnecting:
            await self.close()
            await self._connect_with_login([(self.endpoint, self.cacert)])
210738
def proxy_reconnect(proxy_name, opts=None):
    '''
    
    '''

    if not opts:
        opts = __opts__

    if 'proxy' not in opts:
        return False  # fail

    proxy_keepalive_fn = proxy_name+'.alive'
    if proxy_keepalive_fn not in __proxy__:
        return False  # fail

    is_alive = __proxy__[proxy_keepalive_fn](opts)
    if not is_alive:
        minion_id = opts.get('proxyid', '') or opts.get('id', '')
        log.info('%s (%s proxy) is down. Restarting.', minion_id, proxy_name)
        __proxy__[proxy_name+'.shutdown'](opts)  # safely close connection
        __proxy__[proxy_name+'.init'](opts)  # reopen connection
        log.debug('Restarted %s (%s proxy)!', minion_id, proxy_name)

    return True
396484
def is_retryable(err):
    
    if isinstance(err, ConnectionClosed):
        # NB: only retryable if we're not mid-streaming
        if err.mid_stream:
            return False
        else:
            return True
    elif isinstance(err, socket.error):
        code = err.args[0]
        return code in CONN_CLOSED_ERRORS
    else:
        return False