code: def _stream(self):
          
          timer = None
          try:
              proc = subprocess.Popen(
                  self.cmd, cwd=self.cwd, env=self.env,
                  stdout=subprocess.PIPE,
                  stderr=subprocess.PIPE
              )
              timer = threading.Timer(
                  self.timeout,
                  kill_proc, [proc, self.cmd, time.time()]
              )
              timer.start()
              yield proc
          finally:
              if timer is not None:
                  timer.cancel()
docs: execute subprocess with timeout
  
          Usage::
  
              >>> with cmd_proc.run_with_timeout() as cmd_proc:
              ...     stdout, stderr = cmd_proc.communicate()
              ...
              >>> assert cmd_proc.proc.return_code == 0, "proc exec failed"