Explicitly lock the specified connection

        :type connection: psycopg2.extensions.connection
        :param connection: The connection to lock
        :param queries.Session session: The session to hold the lock
424425
def lock(self, connection, session):
        
        cid = id(connection)
        try:
            self.connection_handle(connection).lock(session)
        except KeyError:
            raise ConnectionNotFoundError(self.id, cid)
        else:
            if self.idle_start:
                with self._lock:
                    self.idle_start = None
        LOGGER.debug('Pool %s locked connection %s', self.id, cid)
978347
def release(self, connection):
        
        with self.lock:
            connection.in_use = False
            self.cond.notify_all()
701724
function(connection) {
      var t = this;
      log.info('removeConnection', 'Conn_' + connection.id);
      connection.disconnect('connection_removed');
      t.connections.remove(connection);
      t.trigger('connection:remove', connection);
    }
1279662
def close_connection(self, connection, force=False):
        """"""
        if force:
            print('PostgresPooled - delegating connection closure')
            try:
                super(PostgresPooled, self).close_connection(connection,
                                                                  force)
            except self.operational_exceptions:
                print('PostgresPooled - failed closing')
            for name, conn in self.pool.iteritems():
                if conn is connection:
                    break
            del self.pool[name]
        else:
            print('PostgresPooled - refusing to close connection')
1353223
def _create_connection_pool(self, conn_params):
    '''
    
    '''
    connection_pools_lock.acquire()
    try:
        # One more read to prevent a read/write race condition (We do this
        # here to avoid the overhead of locking each time we get a connection.)
        if (self.alias not in connection_pools or
            connection_pools[self.alias]['settings'] != self.settings_dict):
            logger.info("Creating connection pool for db alias %s" % self.alias)
            logger.info("  using MIN_CONNS = %s, MAX_CONNS = %s, TEST_ON_BORROW = %s" % (self._min_conns,
                                                                                         self._max_conns,
                                                                                         self._test_on_borrow))

            from psycopg2 import pool
            connection_pools[self.alias] = {
                'pool': pool.ThreadedConnectionPool(self._min_conns, self._max_conns, **conn_params),
                'settings': dict(self.settings_dict),
            }
    finally:
        connection_pools_lock.release()
788596
def remove(self, connection):
        ''''''
        key = (connection.host, connection.port)
        with self._lock:
            found = self._connections.pop(key, None)
        try:
            self.close_connection(found)
        except Exception as exc:
            logger.warn('Failed to close %s: %s', connection, exc)
        return found
584070
def on_connection_blocked(self, method_frame):
        
        LOGGER.warning('Connection blocked: %s', method_frame)
        self.state = self.STATE_BLOCKED
        if self.on_unavailable:
            self.on_unavailable(self)
662410
def get_connection(self):
        
        database = {
            'data': _databases.setdefault(self.identifier, defaultdict(dict)),
            'lock': _locks.setdefault(self.identifier, Lock()),
            'counters': _counters
        }
        return database
1062800
def release(self, lock_transactions=None):
        

        self.personal_lock.release()

        self.with_count -= 1

        if lock_transactions is None:
            lock_transactions = self.lock_transactions

        if not lock_transactions:
            self.db_state.lock.release()
            return

        try:
            # If the connection is closed, an exception is thrown
            in_transaction = self.in_transaction
        except sqlite3.ProgrammingError:
            in_transaction = False

        # The transaction lock should be released only if:
        # 1) the connection was previously in a transaction and now it isn't
        # 2) the connection wasn't previously in a transaction and still isn't
        if (self.was_in_transaction and not in_transaction) or not in_transaction:
            if self.with_count == 0: # This is for nested with statements
                self.db_state.active_connection = None
                self.db_state.transaction_lock.release()

        self.db_state.lock.release()
301592
def release(self, connection: Connection, reuse: bool=True):
        '''
        '''
        yield from self._condition.acquire()
        self.busy.remove(connection)

        if reuse:
            self.ready.add(connection)

        self._condition.notify()
        self._condition.release()
222202
def lock(self, instance_id):
        '''
        
        '''
        nt_ks = self.compute_conn
        response = nt_ks.servers.lock(instance_id)
        return True
942690
def _threadsafe_get_connection(self):
        """"""
        self._lock.acquire()
        try:
            next = self._nextConnection
            con = PooledDBConnection(self, self._connections[next])
            next += 1
            if next >= len(self._connections):
                next = 0
            self._nextConnection = next
            return con
        finally:
            self._lock.release()
367522
def release(self, connection):
        ""
        self._checkpid()
        if connection.pid != self.pid:
            return
        self._in_use_connections.remove(connection)
        # discard connection with unread response
        if connection.awaiting_response:
            connection.disconnect()
            self._created_connections -= 1
        else:
            self._available_connections.append(connection)
1316685
function Session(connection, id) {
  Session.super_.call(this);
  this._connection = connection;
  this._id = id;
  this._plugins = {};

  if (this._connection.getOptions()['keepalive']) {
    this._startKeepAlive();
  }
  var session = this;
  connection.on('close', function() {
    session._destroy();
  });
}
520015
public void lock(String key, String request) throws InterruptedException {
        //get connection
        Object connection = getConnection();
        String result ;
        for (; ;) {
            if (connection instanceof Jedis){
                result = ((Jedis)connection).set(lockPrefix + key, request, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, 10 * TIME);
                if (LOCK_MSG.equals(result)){
                    ((Jedis) connection).close();
                }
            }else {
                result = ((JedisCluster)connection).set(lockPrefix + key, request, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, 10 * TIME);
            }

            if (LOCK_MSG.equals(result)) {
                break;
            }

            Thread.sleep(sleepTime);
        }

    }
375232
def connection(self):
        
        connection = getattr(self.state, "connection", None)
        if connection is None:
            connection = self.state.connection = pika.BlockingConnection(
                parameters=self.parameters)
            self.connections.add(connection)
        return connection
1289741
def connect(self):
        
        connection = psycopg2.connect(
            host=self.host,
            port=self.port,
            database=self.database,
            user=self.user,
            password=self.password)
        connection.set_client_encoding('utf-8')
        return connection