def _advance_iterator(iterator: Iterator, n: int):
    """ Little helper to advance an iterator by n items """
    for i in range(n):
        try:
            next(iterator)
        except StopIteration:
            raise RuntimeError('Trying to advance iterator by {} but iterator raised StopIteration exception on call to next with index {}.'.format(n, i))
    return n
 Little helper to advance an iterator by n items 
kosmos-2/infinibatch/infinibatch/iterators.py