class_docstr: A DirectoryWatcher wraps a loader to load from a sequence of paths.
  
  A loader reads a path and produces some kind of values as an iterator. A
  DirectoryWatcher takes a directory, a factory for loaders, and optionally a
  path filter and watches all the paths inside that directory.
  
  This class is only valid under the assumption that only one path will be
  written to by the data source at a time and that once the source stops writing
  to a path, it will start writing to a new path that's lexicographically
  greater and never come back. It uses some heuristics to check whether this is
  true based on tracking changes to the files' sizes, but the check can have
  false negatives. However, it should have no false positives.
docstr: Constructs a new DirectoryWatcher.
  
  Args:
    directory: The directory to load files from.
    loader_factory: A factory for creating loaders. The factory should take a
      path and return an object that has a Load method returning an
      iterator that will yield all events that have not been yielded yet.
    path_filter: If specified, only paths matching this filter are loaded.
  
  Raises:
    ValueError: If path_provider or loader_factory are None.
docstr_tok: ["Constructs","a","new","DirectoryWatcher",".","Args",":","directory",":","The","directory","to","load","files","from",".","loader_factory",":","A","factory","for","creating","loaders",".","The","factory","should","take","a","path","and","return","an","object","that","has","a","Load","method","returning","an","iterator","that","will","yield","all","events","that","have","not","been","yielded","yet",".","path_filter",":","If","specified",",","only","paths","matching","this","filter","are","loaded",".","Raises",":","ValueError",":","If","path_provider","or","loader_factory","are","None","."]
code: def __init__(
      self, directory, loader_factory, path_filter=lambda x: True
  ):
      """Constructs a new DirectoryWatcher.
  
      Args:
        directory: The directory to load files from.
        loader_factory: A factory for creating loaders. The factory should take a
          path and return an object that has a Load method returning an
          iterator that will yield all events that have not been yielded yet.
        path_filter: If specified, only paths matching this filter are loaded.
  
      Raises:
        ValueError: If path_provider or loader_factory are None.
      """
      if directory is None:
          raise ValueError("A directory is required")
      if loader_factory is None:
          raise ValueError("A loader factory is required")
      self._directory = directory
      self._path = None
      self._loader_factory = loader_factory
      self._loader = None
      self._path_filter = path_filter
      self._ooo_writes_detected = False
      # The file size for each file at the time it was finalized.
      self._finalized_sizes = {}
  
file_path: tensorboard/tensorboard/backend/event_processing/directory_watcher.py
imports: import bisect
  from tensorboard.backend.event_processing import io_wrapper
  from tensorboard.compat import tf
  from tensorboard.util import io_util
  from tensorboard.util import tb_logging
label_desc: Use image node_id 1 to create a new DirectoryWatcher object  with example: obj = DirectoryWatcher(directory, loader_factory, path_filter)