-
Notifications
You must be signed in to change notification settings - Fork 2
/
child.py
85 lines (68 loc) · 2.76 KB
/
child.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
import os
import time
import subprocess
from utils.ADPChild import ADPChild
from utils.loader import load_from_yaml
import logging
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--id", type=int, help='set child id')
parser.add_argument("--exp_name", type=str, help='exp name')
parser.add_argument("--args_file", type=str, default='./args.yml', help='path to args file')
line_args = parser.parse_args()
file_args = load_from_yaml(line_args.args_file)
print(line_args)
print(file_args)
# logging.basicConfig(filename=f'example.log',level=logging.DEBUG)
time.sleep(10)
if __name__ == "__main__":
print("starting up")
child = ADPChild(line_args.id,
game=file_args.game,
args_file=line_args.args_file,
length=file_args.game_len,
lvl_dir=file_args.lvl_dir,
init_lvl=f"{file_args.game}_{file_args.init_lvl}",
prefix=os.path.join(file_args.result_prefix, f"results_{line_args.exp_name}"))
#logging.debug(f"child {child.id} alive signal sent")
start = time.time()
print(start)
done = False
while not done:
try:
while not child.hasTask():
# if you're waiting for a task and
# your alive flag is removed by the parent
# kill yourself.
if not os.path.exists(child.alive) or os.path.exists(child.alive + '.cycle'):
done = True
break
time.sleep(5)
if not done:
# print("found task")
child.recieveTaskAndReturnAnswer()
except KeyboardInterrupt as e:
print(e)
child.pair.env.close()
import sys
sys.exit(0)
# done = True
#check for id.txt.done files. If so, do NOT launch sbatch command.
# placeChildFlag(os.path.join(self.root, self.subfolders['send_to_parent'], f'dead{self.id}.txt')
if os.path.exists(child.alive):
os.remove(child.alive)
if os.path.exists(child.alive + '.done'):
print("task completely finished")
else:
if os.path.exists(child.alive + '.cycle'):
os.remove(child.alive + '.cycle')
print(f"refreshing worker {child.id}")
import platform
if platform.system() == "Linux":
os.system(f'bash refreshWorker.sh {line_args.exp_name} {line_args.args_file} {line_args.id}')
elif platform.system() == "Windows":
# p = subprocess.Popen(f'pwsh -w hidden -file refreshWorker.ps1 -i {line_args.id} -expname {line_args.exp_name} -fname {line_args.args_file}')
# print(p.pid)
pass
print("stuff")
child.pair.env.close()