code: def tail_logs(
      prefix, stdout_tail, stderr_tail, echo, has_log_updates
  ):
      def _available_logs(tail, stream, echo, should_persist=False):
          # print the latest batch of lines
          try:
              for line in tail:
                  if should_persist:
                      line = set_should_persist(line)
                  else:
                      line = refine(line, prefix=prefix)
                  echo(
                      line.strip().decode("utf-8", errors="replace"),
                      stream,
                      no_bold=True,
                  )
          except Exception as ex:
              echo(
                  "%s[ temporary error in fetching logs: %s ]"
                  % (to_unicode(prefix), ex),
                  "stderr",
              )
  
      start_time = time.time()
      next_log_update = start_time
      log_update_delay = 1
      while has_log_updates():
          if time.time() > next_log_update:
              _available_logs(stdout_tail, "stdout", echo)
              _available_logs(stderr_tail, "stderr", echo)
              now = time.time()
              log_update_delay = update_delay(now - start_time)
              next_log_update = now + log_update_delay
  
          # This sleep should never delay log updates. On the other hand,
          # we should exit this loop when the task has finished without
          # a long delay, regardless of the log tailing schedule
          time.sleep(min(log_update_delay, 5.0))
      # It is possible that we exit the loop above before all logs have been
      # tailed.
      _available_logs(stdout_tail, "stdout", echo)
      _available_logs(stderr_tail, "stderr", echo)
  
file_path: metaflow/metaflow/mflog/__init__.py
imports: import math
  import time
  from .mflog import refine, set_should_persist
  from metaflow.util import to_unicode
  from metaflow.exception import MetaflowInternalError
label_desc: Use image node_id 4 for calling a global function with example usage: tail_logs(prefix, stdout_tail, stderr_tail, echo, has_log_updates) without return types