def _update_stopped_suite_info(key): """Use "cylc ls-checkpoints" to obtain info of stopped suite.""" host, owner, suite = key cmd = ["cylc", "ls-checkpoints"] if host: cmd.append("--host=" + host) if owner: cmd.append("--user="******"--debug") else: stderr = PIPE cmd += [suite, "0"] # checkpoint 0 is latest checkpoint result = {} try: proc = Popen(cmd, stdin=open(os.devnull), stderr=stderr, stdout=PIPE, preexec_fn=os.setpgrp) except OSError: return result else: out, err = proc.communicate() if proc.wait(): # non-zero return code if cylc.flags.debug: sys.stderr.write(err) return result finally: if proc.poll() is None: try: os.killpg(proc.pid, signal.SIGTERM) except OSError: pass cur = None for line in out.splitlines(): if not line.strip(): continue if line.startswith("#"): cur = line elif cur == "# CHECKPOINT ID (ID|TIME|EVENT)": result = { KEY_UPDATE_TIME: timestr_to_seconds(line.split("|")[1]), KEY_STATES: ({}, {}) } elif cur == "# TASK POOL (CYCLE|NAME|SPAWNED|STATUS|HOLD_SWAP)": point, _, _, state, _ = line.split("|") # Total count of a state result[KEY_STATES][0].setdefault(state, 0) result[KEY_STATES][0][state] += 1 # Count of a state per cycle try: point = int(point) # Allow integer sort, if possible except ValueError: pass result[KEY_STATES][1].setdefault(point, {}) result[KEY_STATES][1][point].setdefault(state, 0) result[KEY_STATES][1][point][state] += 1 return result
def _update_stopped_suite_info(key): """Use "cylc ls-checkpoints" to obtain info of stopped suite.""" host, owner, suite = key cmd = ["cylc", "ls-checkpoints"] if host: cmd.append("--host=" + host) if owner: cmd.append("--user="******"--debug") else: stderr = PIPE cmd += [suite, "0"] # checkpoint 0 is latest checkpoint result = {} try: proc = Popen( cmd, stdin=open(os.devnull), stderr=stderr, stdout=PIPE, preexec_fn=os.setpgrp) except OSError: return result else: out, err = proc.communicate() if proc.wait(): # non-zero return code if cylc.flags.debug: sys.stderr.write(err) return result finally: if proc.poll() is None: try: os.killpg(proc.pid, signal.SIGTERM) except OSError: pass cur = None for line in out.splitlines(): if not line.strip(): continue if line.startswith("#"): cur = line elif cur == "# CHECKPOINT ID (ID|TIME|EVENT)": result = { KEY_UPDATE_TIME: timestr_to_seconds(line.split("|")[1]), KEY_STATES: ({}, {})} elif cur == "# TASK POOL (CYCLE|NAME|SPAWNED|STATUS|HOLD_SWAP)": point, _, _, state, _ = line.split("|") # Total count of a state result[KEY_STATES][0].setdefault(state, 0) result[KEY_STATES][0][state] += 1 # Count of a state per cycle try: point = int(point) # Allow integer sort, if possible except ValueError: pass result[KEY_STATES][1].setdefault(point, {}) result[KEY_STATES][1][point].setdefault(state, 0) result[KEY_STATES][1][point][state] += 1 return result