def _getconn(self, key=None):
    "Get a free connection and assign it to 'key' if not None."
    if self.closed:
        raise PoolError('connection pool is closed')
    if (key is None):
        key = self._getkey()
    if (key in self._used):
        return self._used[key]
    if self._pool:
        self._used[key] = conn = self._pool.pop()
        self._rused[id(conn)] = key
        return conn
    else:
        if (len(self._used) == self.maxconn):
            raise PoolError('connection pool exhausted')
        return self._connect(key)
Get a free connection and assign it to 'key' if not None.
def _getconn(self, key=None):
    
    if self.closed:
        raise PoolError('connection pool is closed')
    if (key is None):
        key = self._getkey()
    if (key in self._used):
        return self._used[key]
    if self._pool:
        self._used[key] = conn = self._pool.pop()
        self._rused[id(conn)] = key
        return conn
    else:
        if (len(self._used) == self.maxconn):
            raise PoolError('connection pool exhausted')
        return self._connect(key)