code: def _subprocess_check_log_output(cmd, cwd, logfile):
      """
      This method runs a process and logs the output to both a log file and stdout
      """
      _LOG.info("Execute (%s): %s", cwd, cmd)
      cmd_base = (
          cmd[0]
          if isinstance(cmd, (list, tuple))
          else cmd.split(" ", 1)[0]
      )
      proc = subprocess.Popen(
          cmd,
          cwd=cwd,
          shell=True,
          bufsize=0,
          stdout=subprocess.PIPE,
          stderr=subprocess.STDOUT,
          encoding="utf-8",
      )
      stdout = ""
      with open(logfile, "a") as f:
          msg = (
              "\n"
              + "-" * 80
              + f"{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}: Execute ({cwd}): {cmd}\n"
              + "-" * 80
          )
          f.write(msg)
          stdout += msg + "\n"
          while True:
              data = proc.stdout.readline()
              stdout += data
              _LOG.debug("%s: %s", cmd_base, data.rstrip("\n"))
              f.write(data)
  
              # process is done if there is no data and the result is valid
              if not data:  # EOF
                  break
  
      proc.wait()
      if proc.returncode != 0:
          raise RuntimeError(
              f"Subprocess failed: {cmd}\nstdout:\n{stdout}"
          )
  
imports: import contextlib
  import datetime
  import os
  import pathlib
  import re
  import subprocess
  import tarfile
  import logging
  from typing import Any, NamedTuple, Union, Tuple, Optional, List, Dict, Callable
  import numpy
  import tvm
  from tvm import relay
  from tvm import autotvm
  from tvm.contrib import utils, graph_executor
  from tvm.relay.backend import Executor, Runtime
  from tvm.relay.backend.utils import mangle_module_name
  from tvm.micro import export_model_library_format
  from tvm.micro.testing.utils import mlf_extract_workspace_size_bytes
label_desc: Use image node_id 1 for calling a global function with example usage: _subprocess_check_log_output(cmd, cwd, logfile) without return types