code: def interactive_command(
      *args: str,
  ) -> Iterator[_InteractiveCommandProcess]:
      """
      Runs a Determined CLI command in a subprocess. On exit, it kills the
      corresponding Determined task if possible before closing the subprocess.
  
      Example usage:
  
      with util.interactive_command("notebook", "start") as notebook:
          for line in notebook.stdout:
              if "Jupyter Notebook is running" in line:
                  break
      """
  
      with subprocess.Popen(
          ("det", "-m", conf.make_master_url()) + args,
          stdin=subprocess.PIPE,
          stdout=subprocess.PIPE,
          env={"PYTHONUNBUFFERED": "1", **os.environ},
      ) as p:
          cmd = _InteractiveCommandProcess(p, detach="--detach" in args)
          if cmd.task_id is None:
              raise AssertionError(
                  "Task ID for '{}' could not be found. "
                  "If it is still active, this command may persist "
                  "in the Determined test deployment...".format(args)
              )
          try:
              yield cmd
          finally:
              subprocess.check_call(
                  [
                      "det",
                      "-m",
                      conf.make_master_url(),
                      str(args[0]),
                      "kill",
                      cmd.task_id,
                  ]
              )
              p.kill()
  
file_path: determined/e2e_tests/tests/command/command.py
imports: import os
  import re
  import subprocess
  from contextlib import contextmanager
  from typing import IO, Any, Iterator, Optional
  import requests
  from determined.common import api
  from determined.common.api import authentication, certs, task_logs
  from tests import api_utils
  from tests import config
label_desc: Use image node_id 1 for calling a global function with example usage: interactive_command() without return types