-
Notifications
You must be signed in to change notification settings - Fork 4
/
kill_run_exps.py
executable file
·61 lines (50 loc) · 1.35 KB
/
kill_run_exps.py
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
#!/usr/bin/env python3
import argparse
import os
import signal
import subprocess
import sys
import time
import exp
parser = argparse.ArgumentParser()
parser.add_argument('exp_path', metavar='<exp file>', type=str)
args = parser.parse_args()
exp_path = args.exp_path
print("\n\n%s[kill_run_exps] It's time to say good-bye, run_exps %s!\n\n"
% (exp.ltime(), exp_path))
p = subprocess.Popen("ps -ef | grep run_exps.py",
stdout=subprocess.PIPE, shell=True)
out, err = p.communicate()
out = out.decode('utf-8')
print(out)
pid = 0
out = out.split('\n')
for line in out:
spltd = line.split()
if len(spltd) < 8:
continue
if spltd[7] != "python":
continue
if os.path.split(spltd[8])[1] != "run_exps.py":
continue
if spltd[9] != exp_path:
continue
pid = int(spltd[1])
break
if pid == 0:
print("the process not found...")
exit(1)
while True:
childs = exp.childs_of(pid, False)
try:
os.kill(pid, signal.SIGTERM)
except OSError as e:
print("error %s while sending SIGTERM" % e)
childs = exp.childs_of(pid, False)
if len(childs) == 0:
break
print("childs of process %s still exists. send signal again after 1 sec" %
pid)
time.sleep(1)
print("\n\n%s[kill_run_exps] Now run_exps %s cleaned up!\n\n" % (
exp.ltime(), exp_path))