def run(self, serial=False): repo = self.repo cmd = self.cmd msg = ' '.join([START_COLOR, '\n', repo, ':'] + cmd + [RESET_COLOR]) shell = UseShellOnSubprocess() if serial: #Print directly to stdout/stderr without buffering. if not IsQuietMode(): Print(msg) p = None try: p = subprocess.Popen(cmd, cwd=repo, shell=shell) except: PrintError('Error executing: ' + ' '.join(cmd) + ' on: ' + repo) if p is not None: p.wait() else: try: p = subprocess.Popen(cmd, cwd=repo, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=shell) except: import os PrintError('Error executing: ' + ' '.join(cmd) + ' on: ' + repo + ' cwd: ' + os.path.abspath('.')) self.output_queue.put( Output(repo, 'Error executing: %s on repo: %s' % (cmd, repo), '', '')) return self.stdout_thread = self._CreateReaderThread(p, 'stdout') self.stderr_thread = self._CreateReaderThread(p, 'stderr') p.wait() self.stdout_thread.join(2) #finish in at most 2 seconds self.stderr_thread.join(2) #finish in at most 2 seconds stdout = AsStr(self.stdout_thread.GetFullOutput()) stderr = AsStr(self.stderr_thread.GetFullOutput()) self._HandleOutput(msg, stdout, stderr)
def run(self): try: for line in self._stream.readlines(): line = AsStr(line) self._output.append(line) self._full_output.append(line) except: import traceback;traceback.print_exc()