code: def capture(stdout=None, stderr=None):
      out = sys.stdout
      err = sys.stderr
      if stdout is not None:
          sys.stdout = stdout
      if stderr is not None:
          sys.stderr = stderr
      try:
          yield
      finally:
          if stdout is not None:
              sys.stdout.seek(0)
              sys.stdout = out
          if stderr is not None:
              sys.stderr.seek(0)
              sys.stderr = err
  
imports: import contextlib
  import multiprocessing
  import os
  import shutil
  import sys
  import tempfile
  import time
  import traceback
  import cloudpickle
  import mock
  from horovod.runner.util.threads import in_thread
label_desc: Use image node_id 4 for calling a global function with example usage: capture(stdout, stderr) without return types