-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathpwrap.py
More file actions
129 lines (114 loc) · 4.06 KB
/
pwrap.py
File metadata and controls
129 lines (114 loc) · 4.06 KB
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
127
128
129
#PW
import concore
import requests
import time
from ast import literal_eval
import os
#time.sleep(7)
timeout_max=20
concore.delay = 0.02
try:
apikey=open(concore.inpath+'1/concore.apikey',newline=None).readline().rstrip()
except:
try:
#perhaps this should be removed for security
apikey=open('./concore.apikey',newline=None).readline().rstrip()
except:
apikey = ''
try:
yuyu=open(concore.inpath+'1/concore.yuyu',newline=None).readline().rstrip()
except:
try:
yuyu=open('./concore.yuyu',newline=None).readline().rstrip()
except:
yuyu = 'yuyu'
try:
name1=open(concore.inpath+'1/concore.name1',newline=None).readline().rstrip()
except:
try:
name1=open('./concore.name1',newline=None).readline().rstrip()
except:
name1 = 'u'
try:
name2=open(concore.inpath+'1/concore.name2',newline=None).readline().rstrip()
except:
try:
name2=open('./concore.name2',newline=None).readline().rstrip()
except:
name2 = 'ym'
try:
init_simtime_u = open(concore.inpath+'1/concore.init1',newline=None).readline().rstrip()
except:
try:
init_simtime_u = open('./concore.init1',newline=None).readline().rstrip()
except:
init_simtime_u = "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]"
with open("./"+name1,"w") as fcopy:
fcopy.write(init_simtime_u)
try:
init_simtime_ym = open(concore.inpath+'1/concore.init2',newline=None).readline().rstrip()
except:
try:
init_simtime_ym = open('./concore.init2',newline=None).readline().rstrip()
except:
init_simtime_ym = "[0.0, 0.0, 0.0]"
print(apikey)
print(yuyu)
print(name1+'='+init_simtime_u)
print(name2+'='+init_simtime_ym)
while not os.path.exists(concore.inpath+'1/'+name2):
time.sleep(concore.delay)
#Nsim = 150
concore.default_maxtime(150)
#init_simtime_u = "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]"
#init_simtime_ym = "[0.0, 0.0, 0.0]"
u = concore.initval(init_simtime_u)
oldu = init_simtime_u
oldt = 0
#initfiles = {'file1': open('./u', 'rb'), 'file2': open('./ym', 'rb')}
#initfiles = {'file1': open('./u', 'rb'), 'file2': open(concore.inpath+'1/ym', 'rb')}
initfiles = {'file1': open('./'+name1, 'rb'), 'file2': open(concore.inpath+'1/'+name2, 'rb')}
# POST Request to /init with u as file1 and ym as file2
r = requests.post('http://www.controlcore.org/init/'+yuyu+apikey, files=initfiles)
while(concore.simtime<concore.maxtime):
print("PW outer loop")
while concore.unchanged():
ym = concore.read(1,name2,init_simtime_ym)
f = {'file1': open(concore.inpath+'1/'+name2, 'rb')}
print("PW: before post ym="+str(ym))
r = requests.post('http://www.controlcore.org/ctl/'+yuyu+apikey+'&fetch='+name1, files=f,timeout=timeout_max)
if r.status_code!=200:
print("bad POST request "+str(r.status_code))
quit()
if len(r.text)!=0:
try:
t=literal_eval(r.text)[0]
except:
print("bad eval "+r.text)
timeout_count = 0
t1 = time.perf_counter()
print("PW: after post status="+str(r.status_code)+" r.content="+str(r.content)+"/"+r.text)
#while r.text==oldu or len(r.content)==0:
while oldt==t or len(r.content)==0:
time.sleep(concore.delay)
print("PW waiting status="+str(r.status_code)+" content="+ r.content.decode('utf-8')+" t="+str(t))
f = {'file1': open(concore.inpath+'1/'+name2, 'rb')}
try:
r = requests.post('http://www.controlcore.org/ctl/'+yuyu+apikey+'&fetch='+name1, files=f,timeout=timeout_max)
except:
print("PW: bad requests")
timeout_count += 1
if r.status_code!=200 or time.perf_counter()-t1 > 1.1*timeout_max: #timeout_count>200:
print("timeout or bad POST request "+str(r.status_code))
quit()
if len(r.text)!=0:
try:
t=literal_eval(r.text)[0]
except:
print("bad eval "+r.text)
oldt = t
oldu = r.text
print("PW: oldu="+oldu+" t="+str(concore.simtime))
concore.write(1,name1,oldu)
#concore.write(1,"u",init_simtime_u)
print("retry="+str(concore.retrycount))