def _update_launcher_status(self): tx_launcher = Launcher() # new pb message for tx has_update = False for launcher in self.container.launcher: modified = False index = launcher.index importance = self._importances[self._launcher_ids[launcher.index]] if importance is not launcher.importance: tx_launcher.importance = importance modified = True terminating = False if index in self.terminating: terminating = True self.terminating.remove(index) if index in self.processes: process = self.processes[index] process.poll() returncode = process.returncode if returncode is None: if not launcher.running: # update running value if len(launcher.output) > 0: launcher.ClearField( 'output') # clear output for new processes self.launcher_full_update = True # request a full update tx_launcher.running = True tx_launcher.returncode = 0 modified = True # read stdout stdout_index = len(launcher.output) while True: try: line = process.stdout.read() stdoutLine = StdoutLine() stdoutLine.index = stdout_index stdoutLine.line = line tx_launcher.output.add().MergeFrom(stdoutLine) stdout_index += 1 modified = True except IOError: # process has no new line break # send termination status if terminating: tx_launcher.terminating = True else: tx_launcher.returncode = returncode tx_launcher.running = False tx_launcher.terminating = False modified = True self.processes.pop(index, None) # remove from watchlist if modified: launcher.MergeFrom(tx_launcher) tx_launcher.index = index self.tx_container.launcher.add().MergeFrom(tx_launcher) tx_launcher.Clear() has_update = True if self.launcher_full_update: self._add_pparams_to_message() self.tx_container.CopyFrom(self.container) self._send_launcher_message(pb.MT_LAUNCHER_FULL_UPDATE) self.launcher_full_update = False elif has_update: self._send_launcher_message(pb.MT_LAUNCHER_INCREMENTAL_UPDATE)
def _update_launcher_status(self): tx_launcher = Launcher() # new pb message for tx has_update = False for launcher in self.container.launcher: modified = False index = launcher.index importance = self._importances[self._launcher_ids[launcher.index]] if importance is not launcher.importance: tx_launcher.importance = importance modified = True terminating = False if index in self.terminating: terminating = True self.terminating.remove(index) if index in self.processes: process = self.processes[index] process.poll() returncode = process.returncode if returncode is None: if not launcher.running: # update running value if len(launcher.output) > 0: launcher.ClearField('output') # clear output for new processes self.launcher_full_update = True # request a full update tx_launcher.running = True tx_launcher.returncode = 0 modified = True # read stdout stdout_index = len(launcher.output) while True: try: line = process.stdout.read() stdoutLine = StdoutLine() stdoutLine.index = stdout_index stdoutLine.line = line tx_launcher.output.add().MergeFrom(stdoutLine) stdout_index += 1 modified = True except IOError: # process has no new line break # send termination status if terminating: tx_launcher.terminating = True else: tx_launcher.returncode = returncode tx_launcher.running = False tx_launcher.terminating = False modified = True self.processes.pop(index, None) # remove from watchlist if modified: launcher.MergeFrom(tx_launcher) tx_launcher.index = index self.tx_container.launcher.add().MergeFrom(tx_launcher) tx_launcher.Clear() has_update = True if self.launcher_full_update: self._add_pparams_to_message() self.tx_container.CopyFrom(self.container) self._send_launcher_message(pb.MT_LAUNCHER_FULL_UPDATE) self.launcher_full_update = False elif has_update: self._send_launcher_message(pb.MT_LAUNCHER_INCREMENTAL_UPDATE)