ansys / pyoptislang

Pythonic interface to optiSLang
https://optislang.docs.pyansys.com
MIT License
15 stars 1 forks source link

Add a get_run_state function at application level #363

Open optislangdeveloper opened 3 days ago

optislangdeveloper commented 3 days ago

📝 Description of the feature

If you use

osl.application.project.start(wait_for_finished=False)

you want to have a way of checking if the run finished.

My current approach of polling while True: status = osl.project.root_system.get_status() if status == "Processing done": print(f'status: {status}') break elif status == "Check failed": print(f'status: {status}') break

does work, but it comes to timing issues when I activate/deactivate certain nodes and call again

osl.application.project.start(wait_for_finished=False)

The issue I noticed is, that the second start call does nothing - my assumption, the first start is not yet at end even though the status is already Processing done.

💡 Steps for implementing the feature

I want to call a function that returns the run state of the application / system based on the same notification system that is used when I call

osl.application.project.start(wait_for_finished=True)

🔗 Useful links and references

proxy_solver_amop_opt_on_amop_validation.txt

PanekOndrej commented 3 days ago

There is implemented check, whether node is not already running at the beginning of the start method and if so, we don't send START command at all. That's probably why the second start does nothing.

if self.__get_project_status() == "PROCESSING":
            already_running = True
            self._logger.debug("Status PROCESSING")

if not already_running:
            self.send_command(
                command=commands.start(self.__password),
                timeout=self.timeouts_register.get_value(current_func_name),
                max_request_attempts=self.max_request_attempts_register.get_value(
                    current_func_name
                ),
            )