MCPcopy Create free account
hub / github.com/ASLP-lab/OSUM / submit

Function submit

OSUM/tools/ssh_launcher.py:96–146  ·  view source on GitHub ↗
(nworker, hostfile, port, sshport, cmd)

Source from the content-addressed store, hash-verified

94
95
96def submit(nworker, hostfile, port, sshport, cmd):
97 if nworker <= 0:
98 return
99 ip_ports = []
100 if hostfile is not None:
101 hosts = parse_hostfile(hostfile)
102 ip_ports = [h + ":" + str(port) for h in hosts]
103 else:
104 assert nworker == 1
105 local_host = "127.0.0.1"
106 hosts = [local_host] * nworker
107 ports = find_available_ports(local_host, nworker)
108 for p in ports:
109 ip_ports.append(local_host + ":" + str(p))
110
111 local_dir = os.getcwd() + "/"
112 working_dir = local_dir
113
114 # thread func to run the job
115 def run(prog):
116 print("launch prog ", prog)
117 try:
118 subprocess.check_call(prog, shell=True)
119 except subprocess.CalledProcessError as e:
120 logging.info("subprocess({}) failed({})! {}".format(
121 e.cmd, e.returncode, e.output))
122 os._exit(-1)
123
124 pass_envs = os.environ.copy()
125 if "HOST_NODE_ADDR" not in os.environ:
126 pass_envs["HOST_NODE_ADDR"] = hosts[0]
127
128 thread_list = []
129 for i in range(nworker):
130 node = hosts[i % len(hosts)]
131
132 # ssh_port_arg = " -p " + str(sshport) + " "
133 prog = get_env(pass_envs) + " cd " + working_dir + "; " + cmd
134 prog = (
135 "ssh -o StrictHostKeyChecking=no "
136 # + ssh_port_arg # no port available in aidi
137 + node + " '" + prog + "'")
138 thread = Thread(target=run, args=(prog, ))
139 thread.setDaemon(True)
140 thread.start()
141 thread_list.append(thread)
142
143 for t in thread_list:
144 t.join()
145 print("thread join success")
146 print("process end success")
147
148
149if __name__ == "__main__":

Callers 1

ssh_launcher.pyFile · 0.85

Calls 4

parse_hostfileFunction · 0.85
find_available_portsFunction · 0.85
get_envFunction · 0.85
startMethod · 0.45

Tested by

no test coverage detected