code: def run_subprocess(
      command, return_code=False, verbose=None, *args, **kwargs
  ):
      """Run command using subprocess.Popen.
  
      Run command and wait for command to complete. If the return code was zero
      then return, otherwise raise CalledProcessError.
      By default, this will also add stdout= and stderr=subproces.PIPE
      to the call to Popen to suppress printing to the terminal.
  
      Parameters
      ----------
      command : list of str | str
          Command to run as subprocess (see subprocess.Popen documentation).
      return_code : bool
          If True, return the return code instead of raising an error if it's
          non-zero.
  
          .. versionadded:: 0.20
      %(verbose)s
      *args, **kwargs : arguments
          Additional arguments to pass to subprocess.Popen.
  
      Returns
      -------
      stdout : str
          Stdout returned by the process.
      stderr : str
          Stderr returned by the process.
      code : int
          The return code, only returned if ``return_code == True``.
      """
      all_out = ""
      all_err = ""
      # non-blocking adapted from https://stackoverflow.com/questions/375427/non-blocking-read-on-a-subprocess-pipe-in-python#4896288  # noqa: E501
      out_q = Queue()
      err_q = Queue()
      control_stdout = "stdout" not in kwargs
      control_stderr = "stderr" not in kwargs
      with running_subprocess(command, *args, **kwargs) as p:
          if control_stdout:
              out_t = Thread(
                  target=_enqueue_output, args=(p.stdout, out_q)
              )
              out_t.daemon = True
              out_t.start()
          if control_stderr:
              err_t = Thread(
                  target=_enqueue_output, args=(p.stderr, err_q)
              )
              err_t.daemon = True
              err_t.start()
          while True:
              do_break = p.poll() is not None
              # read all current lines without blocking
              while True:  # process stdout
                  try:
                      out = out_q.get(timeout=0.01)
                  except Empty:
                      break
                  else:
                      out = out.decode("utf-8")
                      log_out = out.removesuffix("\n")
                      logger.info(log_out)
                      all_out += out
  
              while True:  # process stderr
                  try:
                      err = err_q.get(timeout=0.01)
                  except Empty:
                      break
                  else:
                      err = err.decode("utf-8")
                      err_out = err.removesuffix("\n")
  
                      # Leave this as logger.warning rather than warn(...) to
                      # mirror the logger.info above for stdout. This function
                      # is basically just a version of subprocess.call, and
                      # shouldn't emit Python warnings due to stderr outputs
                      # (the calling function can check for stderr output and
                      # emit a warning if it wants).
                      logger.warning(err_out)
                      all_err += err
  
              if do_break:
                  break
      output = (all_out, all_err)
  
      if return_code:
          output = output + (p.returncode,)
      elif p.returncode:
          stdout = all_out if control_stdout else None
          stderr = all_err if control_stderr else None
          raise subprocess.CalledProcessError(
              p.returncode, command, output=stdout, stderr=stderr
          )
  
      return output
  
imports: import fnmatch
  import gc
  import hashlib
  import inspect
  import os
  import subprocess
  import sys
  import traceback
  import weakref
  from contextlib import ExitStack, contextmanager
  from importlib.resources import files
  from math import log
  from queue import Empty, Queue
  from string import Formatter
  from textwrap import dedent
  from threading import Thread
  import numpy
  from decorator import FunctionMaker
  from ._logging import logger, verbose, warn
  from .check import _check_option, _validate_type
label_desc: Use image node_id 7 for calling a global function with example usage: run_subprocess(command, return_code, verbose) and returns: output