Skip to content

Commit 7f0ea59

Browse files
committed
Merge branch 'simulation' into v4.1.0-status20260123
2 parents a0b413e + 4f65db9 commit 7f0ea59

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,15 +1185,15 @@ def simulate(
11851185
cmd_definition = om_cmd.definition()
11861186
returncode = self._session.run_model_executable(cmd_run_data=cmd_definition)
11871187
# and check returncode *AND* resultfile
1188-
if returncode != 0 and self._result_file.is_file():
1188+
if returncode != 0:
11891189
# check for an empty (=> 0B) result file which indicates a crash of the model executable
11901190
# see: https://github.com/OpenModelica/OMPython/issues/261
11911191
# https://github.com/OpenModelica/OpenModelica/issues/13829
1192-
if self._result_file.size() == 0:
1192+
if self._result_file.is_file() and self._result_file.size() == 0:
11931193
self._result_file.unlink()
11941194
raise ModelicaSystemError("Empty result file - this indicates a crash of the model executable!")
11951195

1196-
logger.warning(f"Return code = {returncode} but result file exists!")
1196+
logger.warning(f"Return code = {returncode} but result file was created!")
11971197

11981198
self._simulated = True
11991199

@@ -2188,9 +2188,9 @@ def worker(worker_id, task_queue):
21882188
try:
21892189
returncode = self.get_session().run_model_executable(cmd_run_data=cmd_definition)
21902190
logger.info(f"[Worker {worker_id}] Simulation {resultpath.name} "
2191-
f"finished with return code: {returncode}")
2192-
except ModelicaSystemError as ex:
2193-
logger.warning(f"Simulation error for {resultpath.name}: {ex}")
2191+
f"finished with return code {returncode}")
2192+
except OMCSessionException as ex:
2193+
logger.warning(f"Error executing {repr(cmd_definition.get_cmd())}: {ex}")
21942194

21952195
# Mark the task as done
21962196
task_queue.task_done()

OMPython/OMCSession.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,20 +800,23 @@ def run_model_executable(cmd_run_data: OMCSessionRunData) -> int:
800800
env=my_env,
801801
cwd=cmd_run_data.cmd_cwd_local,
802802
timeout=cmd_run_data.cmd_timeout,
803-
check=True,
803+
check=False,
804804
)
805805
stdout = cmdres.stdout.strip()
806806
stderr = cmdres.stderr.strip()
807807
returncode = cmdres.returncode
808808

809-
logger.debug("OM output for command %s:\n%s", repr(cmdl), stdout)
809+
if returncode != 0:
810+
logger.warning("OM executable run %s with returncode=%d and stdout:\n%s",
811+
repr(cmdl), returncode, stdout)
812+
else:
813+
logger.debug("OM executable run %s with stdout:\n%s", repr(cmdl), stdout)
810814

811815
if stderr:
812816
raise OMCSessionException(f"Error running model executable {repr(cmdl)}: {stderr}")
817+
813818
except subprocess.TimeoutExpired as ex:
814819
raise OMCSessionException(f"Timeout running model executable {repr(cmdl)}") from ex
815-
except subprocess.CalledProcessError as ex:
816-
raise OMCSessionException(f"Error running model executable {repr(cmdl)}") from ex
817820

818821
return returncode
819822

0 commit comments

Comments
 (0)