code: def tail_logfile(
      header: str,
      file: str,
      dst: TextIO,
      finished: Event,
      interval_sec: float,
  ):
      while not os.path.exists(file):
          if finished.is_set():
              return
          time.sleep(interval_sec)
  
      with open(file) as fp:
          while True:
              line = fp.readline()
  
              if line:
                  dst.write(f"{header}{line}")
              else:  # reached EOF
                  if finished.is_set():
                      # log line producer is finished
                      break
                  else:
                      # log line producer is still going
                      # wait for a bit before looping again
                      time.sleep(interval_sec)
  
file_path: pytorch/torch/distributed/elastic/multiprocessing/tail_log.py
imports: import logging
  import os
  import time
  from concurrent.futures._base import Future
  from concurrent.futures.thread import ThreadPoolExecutor
  from threading import Event
  from typing import Dict, List, Optional, TextIO
label_desc: Use image node_id 1 for calling a global function with example usage: tail_logfile(header, file, dst, finished, interval_sec) without return types