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
ValueError: Cannot have more than one active ZOS instance #19
Comments
Hi @Omnistic, thanks for notifying us about this problem. This exception is raised from zpcore.py#L289, when creating an instance of the Can you debug this code to confirm that the exception is raised as soon as you run this line? zos = zp.ZOS() This problem is quite weird and probably not related to the connection with OpticStudio, as this exception should already be raised before creating the connection. It might be related to other parts of your setup. Which development environment do you use? |
I turned-off my computer to go to lunch, and tried the following when I returned to work import zospy as zp
zos = zp.ZOS() This time it worked once. But subsequent call to that snippet would produce the error. Even if I close OpticStudio entirely. I will try to restart my computer again to see if it makes a difference. |
I'm having difficulty understanding what's happening. It seems that when I do restart my computer I can get it to work once, but then get the ValueError: Cannot have more than one active ZOS instance Even though with the OS template I can still connect. Could it have to do with how Ansys manage OS licence as oppose to Zemax previously? Its kind of hard to debug cause I need to restart my computer everytime. |
It is actually correct that the second call to that snippet produces the error. Only one instance of the You can check if there is already an existing instance of the zp.ZOS._instances If this returns an empty set, there are no instances; if it returns a set with a single element, there is already an instance and any subsequent calls to Another way to check for instances:
By the way, which development environment are you using? If you are using Spyder, Jupyter or anything else running an ipython kernel, a |
I'm using JupyterLab 3.3.2 and restarting the Kernel works! Sorry I didn't think about that, with the boilerplate code from OpticStudio this is not necessary. Is there any other way other than restarting the Kernel? I tried del zos without success. Thanks for your help! |
Nice that has been sorted out. |
Okay, but this should work as well. It might be that the Meanwhile, it may be useful to know that you can safely reuse an existing |
This comment was marked as off-topic.
This comment was marked as off-topic.
This is a good question, but not related to this issue, so it's better to create a new discussion for this. Thanks! |
Hi @Omnistic, I looked into the problem with deleting the import zospy as zp
print(zp.ZOS._instances)
zos = zp.ZOS()
print(zp.ZOS._instances)
del zos
print(zp.ZOS._instances) The first and last print statement should return an empty set, the second a set with a single element. |
Hi @crnh, Using your message I managed to understand my mistake. The problem was that upon calling del zos The Interactive Extension remains connected in OpticStudio (the Status window displays: Connected). If, after calling del zos I manually Terminate the interactive extension window in OpticStudio and open a new one. Then it seems to be fine. Sorry for the trouble, I guess I expected again a behaviour like the boilerplate code that OpticStudio generates. Do you think there could be a way to avoid having to manually Terminate the interactive extension in OpticStudio? Thanks for your help. |
Ah, that makes sense, thanks for checking this! As far as I know, it is possible to close the extension / standalone OpticStudio instance by calling Regarding the OpticStudio boilerplate code: it completely ignores that you can't create a second connection, and if you try to do so, it will happily return a new reference to the existing connection without telling you it's not a new connection. If you treat this connection as a new connection, you may run into problems, and that's why @LucVV decided to implement the |
I'm using OS 2023 R1.03 Premium with Python 3.10.9, Pythonnet 3.0.1
After installing ZOSPy, when I try to use:
I get a
This happens even after a fresh restart of my computer. My OS is setup with Programming..Interactive Extension (the OS boilerplate interactive extension code works for me). Is there anything I should do to clear any pre-existing connection? Thanks for your help.
The text was updated successfully, but these errors were encountered: