

def _connect(self, *args, **kwargs):
    while True:
        try:
            (ts, conn) = heapq.heappop(self._connections)
            key = self.conn_key(conn)
        except IndexError:
            ts = conn = None
            logger.debug('No connection available in pool.')
            break
        else:
            if self._is_closed(key, conn):
                logger.debug('Connection %s was closed.', key)
                ts = conn = None
                self._closed.discard(key)
            elif (args.stale_timeout and self._is_stale(ts)):
                logger.debug('Connection %s was stale, closing.', key)
                self._close(conn, True)
                self._closed.discard(key)
                ts = conn = None
            else:
                break
    if (conn is None):
        if (self.max_connections and (len(self._in_use) >= self.max_connections)):
            raise ValueError('Exceeded maximum connections.')
        conn = super(PooledDatabase, self)._connect(*args, **kwargs)
        ts = time.time()
        key = self.conn_key(conn)
        logger.debug('Created new connection %s.', key)
    self._in_use[key] = ts
    return conn

dataset/ETHPy150Open coleifer/peewee/playhouse/pool.py PooledDatabase._connect/VarMisuse@114/148 `self`->`args`