code: def log_subprocess_output(i, p, output_dir, tag, start, end):
      """Capture the output of each subprocess and log it in the parent process.
      The first subprocess's output is logged in realtime. The output from the
      other subprocesses is buffered and then printed all at once (in order) when
      subprocesses finish.
      """
      outfile = os.path.join(
          output_dir, "%s_range_%s_%s.stdout" % (tag, start, end)
      )
      logger.info("# " + "-" * 76 + " #")
      logger.info(
          "stdout of subprocess %s with range [%s, %s]"
          % (i, start + 1, end)
      )
      logger.info("# " + "-" * 76 + " #")
      if i == 0:
          # Stream the piped stdout from the first subprocess in realtime
          with open(outfile, "w") as f:
              for line in iter(p.stdout.readline, b""):
                  print(line.rstrip())
                  f.write(str(line))
          p.stdout.close()
          ret = p.wait()
      else:
          # For subprocesses >= 1, wait and dump their log file
          ret = p.wait()
          with open(outfile, "r") as f:
              print("".join(f.readlines()))
      assert ret == 0, "Range subprocess failed (exit code: {})".format(
          ret
      )
  
file_path: dense-pose/detectron/utils/subprocess.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import os
  import yaml
  import numpy
  import subprocess
  import cPickle
  from six.moves import shlex_quote
  from detectron.core.config import cfg
  import logging
label_desc: Use image node_id 2 for calling a global function with example usage: log_subprocess_output(i, p, output_dir, tag, start, end) without return types