-
Notifications
You must be signed in to change notification settings - Fork 4
/
run_exps.py
executable file
·126 lines (106 loc) · 3.21 KB
/
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
"Help performance evaluation experiments automation"
__author__ = "SeongJae Park"
__email__ = "[email protected]"
__copyright__ = "Copyright (c) 2013-2020, SeongJae Park"
__license__ = "GPLv2"
import argparse
import os
import signal
import sys
import time
import exp
def parse_lines(f):
START = "start "
MAIN = "main "
BACK = "back "
END = "end "
CHECK = "check "
exps = []
starts = []
mains = []
backs = []
ends = []
checks = []
prevline = ''
for line in f:
if line.startswith('#'):
continue
line = line.strip('\n').lstrip()
if line.endswith('\\'):
prevline += line[:-1]
continue
line = prevline + line
prevline = ''
if line.startswith(START):
starts.append(line[len(START):])
elif line.startswith(MAIN):
mains.append(line[len(MAIN):])
elif line.startswith(BACK):
backs.append(line[len(BACK):])
elif line.startswith(END):
ends.append(line[len(END):])
elif line.startswith(CHECK):
checks.append(line[len(CHECK):])
elif len(line.split()) == 0 and len(mains) > 0:
exps.append(exp.Exp(starts, mains, backs, ends, checks))
starts = []
mains = []
backs = []
ends = []
checks = []
if len(mains) != 0:
exps.append(exp.Exp(starts, mains, backs, ends, checks))
return exps
def parse_file(filename):
f = sys.stdin
if filename != 'stdin':
f = open(filename)
exps = parse_lines(f)
if filename != 'stdin':
f.close()
return exps
got_sigterm = False
current_exps = []
def sig_handler(signal, frame):
global current_exps
global got_sigterm
print('[run_exps] received signal %s' % signal)
got_sigterm = True
for exp in current_exps:
exp.terminate_tasks()
exit(1)
if __name__ == '__main__':
RETRY_LIMIT = 10
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', '-v', action='store_true',
help='Make some noisy log')
parser.add_argument('--silence', '-s', action='store_true',
help='Do not print log message at all')
parser.add_argument('--dryrun', action='store_true',
help='print what command will be executed only')
parser.add_argument('exp_files', metavar='<file>', nargs='+',
help='experiment spec file')
args = parser.parse_args()
signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
dryrun = args.dryrun
if args.verbose:
exp.verbose = True
if args.silence:
exp.silence = True
for exp_file in args.exp_files:
current_exps = parse_file(exp_file)
if dryrun:
print(current_exps)
continue
for exp in current_exps:
success = False
nr_retry = 0
while not success and nr_retry < RETRY_LIMIT:
# wait until sighandler do cleaning and exit().
if got_sigterm:
time.sleep(1)
continue
success = exp.execute()
nr_retry += 1