code: def _shutdown_proc(p, timeout):
      """Wait for a proc to shut down, then terminate or kill it after `timeout`."""
      freq = 10  # how often to check per second
      for _ in range(1 + timeout * freq):
          p.terminate()
          ret = p.poll()
          if ret is not None:
              logging.info("Shutdown gracefully.")
              return ret
          time.sleep(1 / freq)
      logging.warning("Killing the process.")
      p.kill()
      return p.wait()
  
imports: import os
  import platform
  import shutil
  import subprocess
  import tempfile
  import time
  from absl import flags
  from absl import logging
  import portpicker
  from pysc2.lib import remote_controller
  from pysc2.lib import stopwatch
label_desc: Use image node_id 1 for calling a global function with example usage: _shutdown_proc(p, timeout) and returns: p, ret