def connection(self):
        """ get a cached connection from the pool """
        
        self._condition.acquire()
        try:
            if (self._maxconnections and self._connections >= self._maxconnections):
                raise TooManyConnections("%d connections are already equal to the max: %d" % (self._connections, self._maxconnections))
            # connection limit not reached, get a dedicated connection
            try: # first try to get it from the idle cache
                con = self._idle_cache.pop(0)
            except __HOLE__: # else get a fresh connection
                con = self.new_connection()
            self._connections += 1
        finally:
            self._condition.release()
        return con
dataset/ETHPy150Open bitly/asyncmongo/asyncmongo/pool.py/ConnectionPool.connection