class_docstr: Performs prefetching from an iterable in separate threads.
  
  Its interface is additionally extended with `ready` method which tells whether
  there is any data waiting for processing and a `retrieved_elements` method
  specifying number of elements retrieved from the iterator.
  
  Yields:
    Prefetched elements from the original iterable.
  
  Raises:
    ValueError: if the buffer_size < 1.
    StopIteration: If the iterable contains no more items.
    Any error thrown by the iterable_function. Note this is not raised inside
      the producer, but after it finishes executing.
class_docstr_tok: ["Performs","prefetching","from","an","iterable","in","separate","threads",".","Its","interface","is","additionally","extended","with","`","ready","`","method","which","tells","whether","there","is","any","data","waiting","for","processing","and","a","`","retrieved_elements","`","method","specifying","number","of","elements","retrieved","from","the","iterator",".","Yields",":","Prefetched","elements","from","the","original","iterable",".","Raises",":","ValueError",":","if","the","buffer_size","<","1",".","StopIteration",":","If","the","iterable","contains","no","more","items",".","Any","error","thrown","by","the","iterable_function",".","Note","this","is","not","raised","inside","the","producer",",","but","after","it","finishes","executing","."]
docstr: Constructs PrefetchIterator.
  
  Args:
    iterable: A python iterable. This is used to build the python prefetcher.
      Note that each iterable should only be passed to this function once as
      iterables aren't thread safe.
    buffer_size (int): Number of elements to keep in the prefetch buffer.
    device (deprecated): Optionally place items from the iterable on the given
      device. If None, the items are returns as given by the iterable. This
      argument is deprecated and the recommended usage is to wrap the
      iterables using utils.device_put or utils.multi_device_put before using
      utils.prefetch.
    num_threads (int): Number of threads.
code: def __init__(
      self,
      iterable: Iterable[types.NestedArray],
      buffer_size: int = 5,
      device: Optional[jax.Device] = None,
      num_threads: int = NUM_PREFETCH_THREADS,
  ):
      """Constructs PrefetchIterator.
  
      Args:
        iterable: A python iterable. This is used to build the python prefetcher.
          Note that each iterable should only be passed to this function once as
          iterables aren't thread safe.
        buffer_size (int): Number of elements to keep in the prefetch buffer.
        device (deprecated): Optionally place items from the iterable on the given
          device. If None, the items are returns as given by the iterable. This
          argument is deprecated and the recommended usage is to wrap the
          iterables using utils.device_put or utils.multi_device_put before using
          utils.prefetch.
        num_threads (int): Number of threads.
      """
  
      if buffer_size < 1:
          raise ValueError("the buffer_size should be >= 1")
      self.buffer = queue.Queue(maxsize=buffer_size)
      self.producer_error = []
      self.end = object()
      self.iterable = iterable
      self.device = device
      self.count = 0
  
      # Start producer threads.
      for _ in range(num_threads):
          threading.Thread(target=self.producer, daemon=True).start()
  
imports: import functools
  import itertools
  import queue
  import threading
  from typing import Callable, Iterable, Iterator, NamedTuple, Optional, Sequence, Tuple, TypeVar
  from absl import logging
  from acme import core
  from acme import types
  from acme.jax import types
  import haiku
  import jax
  import jax.numpy
  import numpy
  import reverb
  import tree
label_desc: Use image node_id 1 to create a new PrefetchIterator object from inherited base classes: core with example: obj = PrefetchIterator(iterable, buffer_size, device, num_threads)