def PrefetchIterator(source_iterator: CheckpointableIterator, buffer_size: int, buffer_in_main_process:bool=False, log_empty_buffer_warning: bool=False):
    """
    An iterator prefetching data into a buffer on a seperate process.

    Args:
        source_iterator: checkpointable iterator to recur over
        buffer_size: number of items to prefetch; this is the maximum number of items held in the prefetch queue
        buffer_in_main_process: use experimental version of PrefetchBuffer that has buffer in main process instead of prefetch process
        log_empty_buffer_warning: log warning message if prefetch buffer is empty, only supported if buffer_in_main_process=True
    """
    if not isinstance(source_iterator, CheckpointableIterator):
        raise ValueError('source_iterator has to be a CheckpointableIterator')
    if buffer_size <= 0:
        raise ValueError('buffer_size must be positive')

    if multiprocessing.get_start_method() != 'fork':
        print('WARNING: \
               PrefetchIterator is only supported on operating system that use fork to create new processes.\
               This excludes Windows.\
               A dummy iterator is inserted instead of a PrefetchIterator.\
               This also means that checkpoints of this iterator pipeline cannot be ported to a system that uses fork.')
        return source_iterator
    else:
        if buffer_in_main_process:
            return _ForkPrefetchIteratorExperimental(source_iterator, buffer_size, log_empty_buffer_warning)
        else:
            return _ForkPrefetchIterator(source_iterator, buffer_size)

    An iterator prefetching data into a buffer on a seperate process.

    Args:
        source_iterator: checkpointable iterator to recur over
        buffer_size: number of items to prefetch; this is the maximum number of items held in the prefetch queue
        buffer_in_main_process: use experimental version of PrefetchBuffer that has buffer in main process instead of prefetch process
        log_empty_buffer_warning: log warning message if prefetch buffer is empty, only supported if buffer_in_main_process=True
    
kosmos-2/infinibatch/infinibatch/iterators.py