-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbatchRunner.py
54 lines (37 loc) · 1.15 KB
/
batchRunner.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
# import setup_path
# import airsim
import os
import time
import subprocess as sp
import shutil
# Number of simulations
Nsim = 10
SAVE_LOG = False
def deleteExistingResults():
print("Deleting any previous existing 'results'")
files = os.listdir()
for file in files:
if "results_" in file:
path = os.path.join(os.getcwd(),file)
shutil.rmtree(path)
if __name__ == "__main__":
deleteExistingResults()
for ip in range(1,Nsim+1):
print(f"Running simulation {ip}")
call = ["python","MultiAgent.py",
"--ip", str(ip),
"--waypoints", str(800)]
if SAVE_LOG:
fout = open(f"stdOutput_{ip}.txt","w")
s = sp.Popen(call, shell=True, stdout=fout)
fout.close()
else:
s = sp.Popen(call, shell=True)
exitCode = s.wait()
if exitCode != 0:
# error happened
print(f"Simulation {ip} failed ...")
print("Killing any AirSim Enviroment")
os.system('TASKKILL /F /IM CityEnviron*')
else:
print(f"Simulation {ip} finished successfully\n")