1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| from json import tool from optparse import Option import subprocess import os import sys from numpy import str_ from sty import fg, bg, ef, rs import time
def commandline(command_line): try: process = subprocess.Popen(command_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = process.communicate() stderr = stderr.decode('utf-8') stdout = stdout.decode('utf-8') except: stderr = "what are you talking about?" stdout = ""
return stderr,stdout
def split_str_by_blank(str_com,split_char = ""): if not split_char: str_list = str_com.split() else: str_list = str_com.split(split_char) return str_list
def command_print_out_err(str_com): str_list = split_str_by_blank(str_com) err , out = commandline(str_list) if err : print("ERROR ! : \n",err) elif out : print("OUTPUT : \n",out) def command_print_out_err_for_deepmd(str_com): str_list = split_str_by_blank(str_com) err , out = commandline(str_list) if err : wall_time_index = err.index("wall time") second_unit_index = err.index("s",wall_time_index) total_time = float(err[wall_time_index+11:second_unit_index]) return total_time elif out : print("OUTPUT : \n",out) if __name__ == "__main__": for i in range (50): current_time = time.strftime("%m-%d_%H-%M-%S", time.localtime()) time_str = command_print_out_err_for_deepmd("dp train input.json --skip-neighbor-stat") with open("lcurve.out","a") as f: f.write("\n"+str(time_str)) print("time !!!-> ",time_str) command_print_out_err("mv lcurve.out"+" "+"lcurve.out-"+current_time)
|