class_docstr: Create multiple dataflow instances and run them each in one thread.
  Collect outputs from them with a queue.
  
  Note:
      1. (Data integrity) An iterator cannot run faster automatically -- what's happening is
         that each thread will create a dataflow iterator.
         There will be ``num_thread`` dataflow running in parallel and **independently**.
         As a result, we have the following guarantee on the dataflow correctness:
  
         a. When ``num_thread=1``, this dataflow produces the same data as the
            given dataflow in the same order.
         b. When ``num_thread>1``, if each sample from the given dataflow is i.i.d.,
            then this dataflow produces the **same distribution** of data as the given dataflow.
            This implies that there will be duplication, reordering, etc.
            You probably only want to use it for training.
  
            For example, if your original dataflow contains no randomness and produces the same first datapoint,
            then after parallel prefetching, the datapoint will be produced ``num_thread`` times
            at the beginning.
            Even when your original dataflow is fully shuffled, you still need to be aware of the
            `Birthday Paradox <https://en.wikipedia.org/wiki/Birthday_problem>`_
            and know that you'll likely see duplicates.
  
         To utilize parallelism with more strict data integrity, you can use
         the parallel versions of :class:`MapData`: :class:`MultiThreadMapData`, :class:`MultiProcessMapData`.
class_docstr_tok: ["Create","multiple","dataflow","instances","and","run","them","each","in","one","thread",".","Collect","outputs","from","them","with","a","queue",".","Note",":","1",".","(","Data","integrity",")","An","iterator","can","not","run","faster","automatically","--","what","'s","happening","is","that","each","thread","will","create","a","dataflow","iterator",".","There","will","be","``","num_thread","``","dataflow","running","in","parallel","and","*","*","independently","*","*",".","As","a","result",",","we","have","the","following","guarantee","on","the","dataflow","correctness",":","a",".","When","``","num_thread=1","``",",","this","dataflow","produces","the","same","data","as","the","given","dataflow","in","the","same","order",".","b",".","When","``","num_thread",">","1","``",",","if","each","sample","from","the","given","dataflow","is","i.i.d.",",","then","this","dataflow","produces","the","*","*","same","distribution","*","*","of","data","as","the","given","dataflow",".","This","implies","that","there","will","be","duplication",",","reordering",",","etc",".","You","probably","only","want","to","use","it","for","training",".","For","example",",","if","your","original","dataflow","contains","no","randomness","and","produces","the","same","first","datapoint",",","then","after","parallel","prefetching",",","the","datapoint","will","be","produced","``","num_thread","``","times","at","the","beginning",".","Even","when","your","original","dataflow","is","fully","shuffled",",","you","still","need","to","be","aware","of","the","`","Birthday","Paradox","<","https",":","\/\/en.wikipedia.org\/wiki\/Birthday_problem",">","`","_","and","know","that","you","'ll","likely","see","duplicates",".","To","utilize","parallelism","with","more","strict","data","integrity",",","you","can","use","the","parallel","versions","of",":","class",":","`","MapData","`",":",":","class",":","`","MultiThreadMapData","`",",",":","class",":","`","MultiProcessMapData","`","."]
docstr: Args:
      get_df ( -> DataFlow): a callable which returns a DataFlow.
          Each thread will call this function to get the DataFlow to use.
          Therefore do not return the same DataFlow object for each call,
          unless your dataflow is stateless.
      num_prefetch (int): size of the queue
      num_thread (int): number of threads
code: def __init__(self, get_df, num_prefetch, num_thread):
      """
      Args:
          get_df ( -> DataFlow): a callable which returns a DataFlow.
              Each thread will call this function to get the DataFlow to use.
              Therefore do not return the same DataFlow object for each call,
              unless your dataflow is stateless.
          num_prefetch (int): size of the queue
          num_thread (int): number of threads
      """
      assert num_thread > 0, num_thread
      assert num_prefetch > 0, num_prefetch
      self.num_thread = num_thread
      self.queue = queue.Queue(maxsize=num_prefetch)
      self.threads = [
          MultiThreadRunner._Worker(get_df, self.queue)
          for _ in range(num_thread)
      ]
  
      try:
          self._size = self.__len__()
      except NotImplementedError:
          self._size = -1
  
imports: import atexit
  import pickle
  import errno
  import traceback
  import itertools
  import multiprocessing
  import os
  import sys
  import uuid
  import weakref
  from contextlib import contextmanager
  import zmq
  from six.moves import queue, range
  from ..utils import logger
  from ..utils.concurrency import StoppableThread, enable_death_signal, ensure_proc_terminate, start_proc_mask_signal
  from ..utils.serialize import dumps_once, loads_once
  from .base import DataFlow, DataFlowReentrantGuard, DataFlowTerminated, ProxyDataFlow
label_desc: Use image node_id 1 to create a new MultiThreadRunner object from inherited base classes: DataFlow with example: obj = MultiThreadRunner(get_df, num_prefetch, num_thread)