@classmethod
def remove_connection(cls, pid, connection):
    """Remove a connection from the pool, closing it if is open.

        :param str pid: The pool ID
        :param connection: The connection to remove
        :type connection: psycopg2.extensions.connection
        :raises: ConnectionNotFoundError

        """
    cls._ensure_pool_exists(pid)
    cls._pools[pid].remove(connection)
