Skip to content

Commit

Permalink
tcp_osl_server.py: Fixed _wait_for_finish method
Browse files Browse the repository at this point in the history
  • Loading branch information
rfahlberg committed Sep 8, 2022
1 parent 784d444 commit 77ea126
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/ansys/optislang/core/tcp_osl_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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...")
Expand Down

0 comments on commit 77ea126

Please sign in to comment.