From 77ea126b4c23edd70b6ea4f6e667c2f82fd94120 Mon Sep 17 00:00:00 2001 From: fahlberg Date: Thu, 8 Sep 2022 19:05:52 +0200 Subject: [PATCH] tcp_osl_server.py: Fixed _wait_for_finish method --- src/ansys/optislang/core/tcp_osl_server.py | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/ansys/optislang/core/tcp_osl_server.py b/src/ansys/optislang/core/tcp_osl_server.py index 9a63baf16..9fabc7f23 100644 --- a/src/ansys/optislang/core/tcp_osl_server.py +++ b/src/ansys/optislang/core/tcp_osl_server.py @@ -1129,7 +1129,7 @@ def start(self, wait_for_finish: bool = True) -> None: self._send_command(commands.start(self.__password)) if wait_for_finish: - self._wait_for_finish("FINISHED", _get_current_timeout(self.__timeout, start_time)) + self._wait_for_finish(_get_current_timeout(self.__timeout, start_time)) def stop(self, wait_for_finish: bool = True) -> None: """Stop project execution. @@ -1153,11 +1153,21 @@ def stop(self, wait_for_finish: bool = True) -> None: """ start_time = time.time() status = self.get_project_status() - if status not in ["FINISHED", "STOPPED"]: + + not_stopped_states = [ + "IDLE", + "FINISHED", + "STOP_REQUESTED", + "STOPPED", + "ABORT_REQUESTED", + "ABORTED", + ] + + if status not in not_stopped_states: self._send_command(commands.stop(self.__password)) if wait_for_finish: - self._wait_for_finish("STOPPED", _get_current_timeout(self.__timeout, start_time)) + self._wait_for_finish(_get_current_timeout(self.__timeout, start_time)) def stop_gently(self, wait_for_finish: bool = True) -> None: """Stop project execution after the current design is finished. @@ -1181,11 +1191,14 @@ def stop_gently(self, wait_for_finish: bool = True) -> None: """ start_time = time.time() status = self.get_project_status() - if status not in ["FINISHED", "STOPPED"]: + + not_gently_stopped_states = ["IDLE", "FINISHED", "STOPPED", "ABORT_REQUESTED", "ABORTED"] + + if status not in not_gently_stopped_states: self._send_command(commands.stop_gently(self.__password)) if wait_for_finish: - self._wait_for_finish("STOPPED", _get_current_timeout(self.__timeout, start_time)) + self._wait_for_finish(_get_current_timeout(self.__timeout, start_time)) def _unregister_listener(self, uuid: str) -> None: """Unregister a listener. @@ -1416,7 +1429,7 @@ def __check_command_response(response: Dict) -> None: message = "Command error: " + str(response) raise OslCommandError(message) - def _wait_for_finish(self, desired_status: str, timeout: Union[float, None]) -> None: + def _wait_for_finish(self, timeout: Union[float, None]) -> None: """Wait on optiSLang to finish the project run. Parameters @@ -1438,7 +1451,7 @@ def _wait_for_finish(self, desired_status: str, timeout: Union[float, None]) -> while True: remain_time = _get_current_timeout(timeout, start_time) status = self.get_project_status() - if status == desired_status: + if status == "FINISHED" or status == "STOPPED" or status == "ABORTED": return self._logger.debug("Waiting for project run to finish...")