Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop / finalize server instance on python delete and process end #875

Open
dkowollik opened this issue Sep 9, 2024 · 3 comments
Open

Stop / finalize server instance on python delete and process end #875

dkowollik opened this issue Sep 9, 2024 · 3 comments
Labels
aps Anything related to Ansys Prime Server enhancement New features or code improvements

Comments

@dkowollik
Copy link

📝 Description of the feature

Hi,
it would be great, if you could exit the server instance (check in license) once one uses the python del operator and once the python process finishes.

💡 Steps for implementing the feature

No response

🔗 Useful links and references

No response

@dkowollik dkowollik added the enhancement New features or code improvements label Sep 9, 2024
@waltersma waltersma added the aps Anything related to Ansys Prime Server label Sep 13, 2024
@waltersma
Copy link
Contributor

waltersma commented Oct 1, 2024

Hi @dkowollik do the following two options deliver what you need in this instance? Thanks

  1. Client.exit()
  2. Launching using context

@dkowollik
Copy link
Author

Hi @waltersma,
You are right, this is doing the job, if everything works fine. Client.exit() does not work, if an error occurs during the script execution at an earlier stage. The server process stays alive and keeps the license. If that happens, one has to search for the process and kill it manually. As a workaround for this, I implemented the following for now:

if __name__ == '__main__':

    prime_client = prime.launch_prime(prime_root=r'C:\Program Files\ANSYS Inc\v242\meshing\Prime')
    try:
        main(prime_client)
        prime_client.exit()
    except:
        t, v, tb = sys.exc_info()
        prime_client.exit()
        six.reraise(t, v, tb)

It seems like each pyansys package uses a different interface for launch and exit (for example: launch, start, stop, restart, exit, with). It would be great to have identical interfaces to launch and close the server. Other pyansys packages also kill the server process once the script ends, an error occurs or the client instance has been deleted. To be more precise the server process is stopped, if it was launched during the session by the client.
There exists a generic pyansys interface that uses the python builtin weakref finalize implementation, see:
https://github.com/ansys/ansys-tools-local-product-launcher/blob/38840c7f8bd01ccc529d6b76d151c1f503d0cb4a/src/ansys/tools/local_product_launcher/product_instance.py#L52
I talked to @greschd, who gave me the above link and implemented the plugin for pyACP. He can help you and explain this much better than I can.

Thanks.

@dkowollik
Copy link
Author

Hi @waltersma,
There is another advantage to use this finalize approach. If you are in debug mode using your IDE and you manually kill the python process, the server is killed and the license is checked in as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aps Anything related to Ansys Prime Server enhancement New features or code improvements
Projects
None yet
Development

No branches or pull requests

2 participants