MCPcopy
hub / github.com/dmlc/dgl / kill_process

Function kill_process

tools/launch.py:36–73  ·  view source on GitHub ↗

ssh to a remote machine and kill the specified processes.

(ip, port, pids)

Source from the content-addressed store, hash-verified

34
35
36def kill_process(ip, port, pids):
37 """ssh to a remote machine and kill the specified processes."""
38 curr_pid = os.getpid()
39 killed_pids = []
40 # If we kill child processes first, the parent process may create more again. This happens
41 # to Python's process pool. After sorting, we always kill parent processes first.
42 pids.sort()
43 for pid in pids:
44 assert curr_pid != pid
45 print("kill process {} on {}:{}".format(pid, ip, port), flush=True)
46 kill_cmd = (
47 "ssh -o StrictHostKeyChecking=no -p "
48 + str(port)
49 + " "
50 + ip
51 + " 'kill {}'".format(pid)
52 )
53 subprocess.run(kill_cmd, shell=True)
54 killed_pids.append(pid)
55 # It's possible that some of the processes are not killed. Let's try again.
56 for i in range(3):
57 killed_pids = get_killed_pids(ip, port, killed_pids)
58 if len(killed_pids) == 0:
59 break
60 else:
61 killed_pids.sort()
62 for pid in killed_pids:
63 print(
64 "kill process {} on {}:{}".format(pid, ip, port), flush=True
65 )
66 kill_cmd = (
67 "ssh -o StrictHostKeyChecking=no -p "
68 + str(port)
69 + " "
70 + ip
71 + " 'kill -9 {}'".format(pid)
72 )
73 subprocess.run(kill_cmd, shell=True)
74
75
76def get_killed_pids(ip, port, killed_pids):

Callers 1

cleanup_procFunction · 0.70

Calls 4

formatMethod · 0.80
appendMethod · 0.80
get_killed_pidsFunction · 0.70
runMethod · 0.45

Tested by

no test coverage detected