@classmethod
def get(cls, pid, session):
    """Get an idle, unused connection from the pool. Once a connection has
        been retrieved, it will be marked as in-use until it is freed.

        :param str pid: The pool ID
        :param queries.Session session: The session to assign to the connection
        :rtype: psycopg2.extensions.connection

        """
    with cls._lock:
        cls._ensure_pool_exists(pid)
        return cls._pools[pid].get(session)
