-
Notifications
You must be signed in to change notification settings - Fork 2
/
concore.py
89 lines (78 loc) · 2.13 KB
/
concore.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
import time
import os
from ast import literal_eval
import sys
#if windows, create script to kill this process
# because batch files don't provide easy way to know pid of last command
# ignored for posix!=windows, because "concorepid" is handled by script
# ignored for docker (linux!=windows), because handled by docker stop
if hasattr(sys, 'getwindowsversion'):
with open("concorekill.bat","w") as fpid:
fpid.write("taskkill /F /PID "+str(os.getpid())+"\n")
try:
iport = literal_eval(open("concore.iport").read())
except:
iport = dict()
try:
oport = literal_eval(open("concore.oport").read())
except:
oport = dict()
s = ''
olds = ''
delay = 1
retrycount = 0
inpath = "./in" #must be rel path for local
outpath = "./out"
#9/12/21
def default_maxtime(default):
global maxtime
try:
maxtime = literal_eval(open(inpath+"1/concore.maxtime").read())
except:
maxtime = default
default_maxtime(100)
def unchanged():
global olds,s
if olds==s:
s = ''
return True
else:
olds = s
return False
def read(port, name, initstr):
global s,simtime,retrycount
time.sleep(delay)
try:
infile = open(inpath+str(port)+"/"+name);
ins = infile.read()
except:
ins = initstr
while len(ins)==0:
time.sleep(delay)
ins = infile.read()
retrycount += 1
s += ins
inval = literal_eval(ins)
simtime = max(simtime,inval[0])
return inval[1:]
def write(port, name, val, delta=0):
global outpath,simtime
if isinstance(val,str):
time.sleep(2*delay)
elif isinstance(val,list)==False:
print("mywrite must have list or str")
quit()
try:
with open(outpath+str(port)+"/"+name,"w") as outfile:
if isinstance(val,list):
outfile.write(str([simtime+delta]+val))
simtime += delta
else:
outfile.write(val)
except:
print("skipping"+outpath+str(port)+"/"+name);
def initval(simtime_val):
global simtime
val = literal_eval(simtime_val)
simtime = val[0]
return val[1:]