prefetch#

anri.io.prefetch(chunks, depth=2)[source]#

Read ahead: produce the items of an iterable in a background thread, up to depth ahead of the consumer.

With stream_sparse(), the next chunk is read and decompressed while the current one is processed, so the disk and the GPU (or CPU) work at the same time instead of in turn. An error in the reader is raised in the consumer.

Parameters:
  • chunks (Iterable) – Any iterable

  • depth (int, default: 2) – Items read ahead at most

Yields:

object – The items of chunks, in order