Skip to content

Commit 8e7d0ee

Browse files
authored
Merge pull request #174 from iprasannamb/fix-x
Fix: Path Construction and ZMQ Fall
2 parents d0348a7 + ebf8093 commit 8e7d0ee

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

concore.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ def safe_literal_eval(filename, defaultValue):
125125
inpath = "./in" #must be rel path for local
126126
outpath = "./out"
127127
simtime = 0
128+
concore_params_file = os.path.join(inpath, "1", "concore.params")
129+
concore_maxtime_file = os.path.join(inpath, "1", "concore.maxtime")
128130

129131
#9/21/22
130132
# ===================================================================
131133
# Parameter Parsing
132134
# ===================================================================
133135
try:
134-
sparams_path = os.path.join(inpath + "1", "concore.params")
136+
sparams_path = concore_params_file
135137
if os.path.exists(sparams_path):
136138
with open(sparams_path, "r") as f:
137139
sparams = f.read()
@@ -171,8 +173,7 @@ def tryparam(n, i):
171173
def default_maxtime(default):
172174
"""Read maximum simulation time from file or use default."""
173175
global maxtime
174-
maxtime_path = os.path.join(inpath + "1", "concore.maxtime")
175-
maxtime = safe_literal_eval(maxtime_path, default)
176+
maxtime = safe_literal_eval(concore_maxtime_file, default)
176177

177178
default_maxtime(100)
178179

@@ -220,7 +221,7 @@ def read(port_identifier, name, initstr_val):
220221
return default_return_val
221222

222223
time.sleep(delay)
223-
file_path = os.path.join(inpath+str(file_port_num), name)
224+
file_path = os.path.join(inpath, str(file_port_num), name)
224225
ins = ""
225226

226227
try:
@@ -283,14 +284,12 @@ def write(port_identifier, name, val, delta=0):
283284
print(f"ZMQ write error on port {port_identifier} (name: {name}): {e}")
284285
except Exception as e:
285286
print(f"Unexpected error during ZMQ write on port {port_identifier} (name: {name}): {e}")
287+
return
286288

287289
# Case 2: File-based port
288290
try:
289-
if isinstance(port_identifier, str) and port_identifier in zmq_ports:
290-
file_path = os.path.join("../"+port_identifier, name)
291-
else:
292-
file_port_num = int(port_identifier)
293-
file_path = os.path.join(outpath+str(file_port_num), name)
291+
file_port_num = int(port_identifier)
292+
file_path = os.path.join(outpath, str(file_port_num), name)
294293
except ValueError:
295294
print(f"Error: Invalid port identifier '{port_identifier}' for file operation. Must be integer or ZMQ name.")
296295
return

concoredocker.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ def safe_literal_eval(filename, defaultValue):
2121
inpath = os.path.abspath("/in")
2222
outpath = os.path.abspath("/out")
2323
simtime = 0
24+
concore_params_file = os.path.join(inpath, "1", "concore.params")
25+
concore_maxtime_file = os.path.join(inpath, "1", "concore.maxtime")
2426

2527
#9/21/22
2628
try:
27-
sparams = open(inpath+"1/concore.params").read()
29+
sparams = open(concore_params_file).read()
2830
if sparams[0] == '"': #windows keeps "" need to remove
2931
sparams = sparams[1:]
3032
sparams = sparams[0:sparams.find('"')]
@@ -46,7 +48,7 @@ def tryparam(n, i):
4648
#9/12/21
4749
def default_maxtime(default):
4850
global maxtime
49-
maxtime = safe_literal_eval(os.path.join(inpath, "1", "concore.maxtime"), default)
51+
maxtime = safe_literal_eval(concore_maxtime_file, default)
5052

5153
default_maxtime(100)
5254

@@ -62,7 +64,7 @@ def read(port, name, initstr):
6264
global s, simtime, retrycount
6365
max_retries=5
6466
time.sleep(delay)
65-
file_path = os.path.join(inpath+str(port), name)
67+
file_path = os.path.join(inpath, str(port), name)
6668

6769
try:
6870
with open(file_path, "r") as infile:
@@ -101,7 +103,7 @@ def read(port, name, initstr):
101103

102104
def write(port, name, val, delta=0):
103105
global simtime
104-
file_path = os.path.join(outpath+str(port), name)
106+
file_path = os.path.join(outpath, str(port), name)
105107

106108
if isinstance(val, str):
107109
time.sleep(2 * delay)

0 commit comments

Comments
 (0)