import traceback


def fetch_data(datagen, idx):
    """ Fetch one batch of data from a data generator """
    try:
        return datagen[idx]
    except Exception as exp:
        traceback.print_exc()
        print()
        raise exp