def run(self, timeout=None):
        def target():
            ui.debug("Starting thread.")
            ui.debug("Calling:", subprocess.list2cmdline(self.cmd))
            try:
                opts = dict()
                if os.name == 'posix':
                    opts = {
                        'preexec_fn': os.setsid,
                        'close_fds': True
                    }
                elif os.name == 'nt':
                    opts = {
                        'creationflags': subprocess.CREATE_NEW_PROCESS_GROUP,
                    }
                kwargs = {
                        "cwd": self.cwd,
                        "env" : self.env
                }
                kwargs.update(opts)
                if self.capture:
                    kwargs["stdout"] = subprocess.PIPE
                    kwargs["stderr"] = subprocess.STDOUT
                self._process = subprocess.Popen(self.cmd, **kwargs)
            except Exception, e:
                self.exception = e
                self.return_type = Process.NOT_RUN
                return
            def read_target():
                self.out = self._process.communicate()[0]
            self._should_stop_reading = False
            self._reading_thread = threading.Thread(target=read_target)
            # Allow Python to exit even if the reading thread is still alive
            # (i.e the process is still running even after we tried to kill it)
            self._reading_thread.daemon = True
            self._reading_thread.start()
            while not self._should_stop_reading and self._reading_thread.is_alive():
                self._reading_thread.join(1)
            self.returncode = self._process.returncode
            if self.returncode == 0:
                ui.debug("Setting return code to Process.OK")
                self.return_type = Process.OK
            ui.debug("Thread terminated.")

        self._thread = threading.Thread(target=target)
        self._thread.start()
        while ((timeout is None or 0 < timeout) and self._thread.is_alive() and
               not SIGINT_EVENT.is_set()):
            self._thread.join(1)
            if timeout is not None:
                timeout -= 1
        if not self._thread.is_alive():
            return
        elif SIGINT_EVENT.is_set():
            self._interrupt()
        else:
            ui.debug("Process timed out")
            self._kill_subprocess()
dataset/ETHPy150Open aldebaran/qibuild/python/qisys/command.py/Process.run/original