diff --git a/OMPython/ModelicaSystem.py b/OMPython/ModelicaSystem.py index 59efe177..29c5b48b 100644 --- a/OMPython/ModelicaSystem.py +++ b/OMPython/ModelicaSystem.py @@ -1145,15 +1145,15 @@ def simulate( cmd_definition = om_cmd.definition() returncode = self._session.run_model_executable(cmd_run_data=cmd_definition) # and check returncode *AND* resultfile - if returncode != 0 and self._result_file.is_file(): + if returncode != 0: # check for an empty (=> 0B) result file which indicates a crash of the model executable # see: https://github.com/OpenModelica/OMPython/issues/261 # https://github.com/OpenModelica/OpenModelica/issues/13829 - if self._result_file.size() == 0: + if self._result_file.is_file() and self._result_file.size() == 0: self._result_file.unlink() raise ModelicaSystemError("Empty result file - this indicates a crash of the model executable!") - logger.warning(f"Return code = {returncode} but result file exists!") + logger.warning(f"Return code = {returncode} but result file was created!") self._simulated = True @@ -2144,9 +2144,9 @@ def worker(worker_id, task_queue): try: returncode = self.get_session().run_model_executable(cmd_run_data=cmd_definition) logger.info(f"[Worker {worker_id}] Simulation {resultpath.name} " - f"finished with return code: {returncode}") - except ModelicaSystemError as ex: - logger.warning(f"Simulation error for {resultpath.name}: {ex}") + f"finished with return code {returncode}") + except OMCSessionException as ex: + logger.warning(f"Error executing {repr(cmd_definition.get_cmd())}: {ex}") # Mark the task as done task_queue.task_done() diff --git a/OMPython/OMCSession.py b/OMPython/OMCSession.py index 861f2a3a..9efbc879 100644 --- a/OMPython/OMCSession.py +++ b/OMPython/OMCSession.py @@ -800,20 +800,23 @@ def run_model_executable(cmd_run_data: OMCSessionRunData) -> int: env=my_env, cwd=cmd_run_data.cmd_cwd_local, timeout=cmd_run_data.cmd_timeout, - check=True, + check=False, ) stdout = cmdres.stdout.strip() stderr = cmdres.stderr.strip() returncode = cmdres.returncode - logger.debug("OM output for command %s:\n%s", repr(cmdl), stdout) + if returncode != 0: + logger.warning("OM executable run %s with returncode=%d and stdout:\n%s", + repr(cmdl), returncode, stdout) + else: + logger.debug("OM executable run %s with stdout:\n%s", repr(cmdl), stdout) if stderr: raise OMCSessionException(f"Error running model executable {repr(cmdl)}: {stderr}") + except subprocess.TimeoutExpired as ex: raise OMCSessionException(f"Timeout running model executable {repr(cmdl)}") from ex - except subprocess.CalledProcessError as ex: - raise OMCSessionException(f"Error running model executable {repr(cmdl)}") from ex return returncode