-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunTorcs
executable file
·114 lines (100 loc) · 2.77 KB
/
runTorcs
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
#!/bin/sh
# python3 torcsGame.py
# pkill torcs
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# ./
# Initialize our own variables:
config_file="./torcs_central/config.json"
verbose=0
stopflag=0
# refreshRate = 5 #minutes
usage="$(basename "$0")
Distributed RL framework for Torcs
usage ./runTorcs [Arguments]
Arguments:
-h show this help text
-s server only
-c worker only
-n erase models and start new session
-e edit config file
-t [/log_path] run tensorboard
Default:
- Both server and client would run on the same computer
Make sure ip address in config is 'localhost'.
- If hosting a server use -s argument.
- If running only worker use -c argument.
Make sure the server IP is set correctly in config
- The trained weights are stored locally as well as on server.
Use -n argument to start a new worker and server on both systems
or on the same machine.
"
killallprocess(){
echo "\n\n\n\n-----------------killing all processes------------------------"
echo " WORKER_PID $TASK_PID"
# echo " SERVER_PID $SERVER_PID"
stopflag=1
kill -INT $TASK_PID
echo " KILLED $TASK_PID"
pkill torcs
echo " torcs $TASK_PID"
# kill -INT $SERVER_PID
# pkill python3
echo "\n\n\n\n--------------------------------------------------------------"
exit 0
}
trap killallprocess INT
# running Torcs for long time causes memory leak or lags. kill the worker and start again
runWorker_loop(){
while true;do
echo "-----------------------------------starting worker-----------------------------------"
python3 torcsGame.py &
TASK_PID=$!
echo "\n\n\n\n--------------------------------------------------------------"
echo " WORKER_PID $TASK_PID"
echo "\n\n\n\n--------------------------------------------------------------"
sleep 5m
kill -INT $TASK_PID
pkill python3
pkill torcs
if [ "$stopflag" -ne 0 ]; then
break
fi
done;
}
while getopts "h?cnset:" opt; do
case "$opt" in
h|\?)
echo "$usage"
exit 0
;;
c) ./runWorker
#runWorker
exit 0
;;
n) rm -rf models/ pulledModels/ resource/ temp/
;;
s) ./runServer
exit 0
;;
e) nano "$config_file"
exit 0
;;
t) echo "tensorboard"
sensible-browser http://localhost:6006 &
tensorboard --logdir=${OPTARG}
exit 0
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
# echo " Leftovers: $@"
# ./runServer &
# SERVER_PID=$!
# echo "SERVER_PID $SERVER_PID"
# sleep 10
# runWorker
# # pkill python3
# echo "KILLED WORKER"
# exit 0