code: def check_subprocess_call(
      cmd, timeout=1, stdout_regex=None, stderr_regex=None
  ):
      """Runs a command in a subprocess with timeout in seconds.
  
      Also checks returncode is zero, stdout if stdout_regex is set, and
      stderr if stderr_regex is set.
      """
      proc = subprocess.Popen(
          cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
      )
  
      def kill_process():
          proc.kill()
  
      timer = threading.Timer(timeout, kill_process)
      try:
          timer.start()
          stdout, stderr = proc.communicate()
  
          if PY3_OR_LATER:
              stdout, stderr = stdout.decode(), stderr.decode()
          if proc.returncode != 0:
              message = (
                  "Non-zero return code: {0}.\nStdout:\n{1}\n"
                  "Stderr:\n{2}"
              ).format(proc.returncode, stdout, stderr)
              raise ValueError(message)
  
          if stdout_regex is not None and not re.search(
              stdout_regex, stdout
          ):
              raise ValueError(
                  "Unexpected stdout: {0!r} does not match:\n{1!r}".format(
                      stdout_regex, stdout
                  )
              )
          if stderr_regex is not None and not re.search(
              stderr_regex, stderr
          ):
              raise ValueError(
                  "Unexpected stderr: {0!r} does not match:\n{1!r}".format(
                      stderr_regex, stderr
                  )
              )
  
      finally:
          timer.cancel()
  
file_path: catboost/contrib/python/scikit-learn/py2/sklearn/externals/joblib/testing.py
imports: import sys
  import warnings
  import os.path
  import re
  import subprocess
  import threading
  from sklearn.externals.joblib._compat import PY3_OR_LATER
label_desc: Use image node_id 2 for calling a global function with example usage: check_subprocess_call(cmd, timeout, stdout_regex, stderr_regex) without return types