You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Several users of ZOSPy complained about being unable to create a new ZOS instance, even after deleting the existing instance using del zos (being unable to create a new instance when another instance exists is by design).
I looked into this and there are two main reasons for this problem:
The use of an interactive Python environment like IPython or Jupyter notebooks. These environments may keep some references to variables even after deleting them, so the existing ZOS instance is not removed by the garbage collector after calling del zos.
The existence of OpticStudioSystem instances. Every OpticStudioSystem contains a reference to the ZOS instance that created it. As a result, there will still be some references to this ZOS instance, and deleting zos will not result in its removal by the garbage collector. It is therefore necessary to
I am not sure if this should be considered a bug, as this is related to how Python works. Furthermore, it is not necessary to delete and recreate ZOS objects, as the same instance can be used to manage all OpticStudioSystem instances. Nevertheless, users expect to be able to delete ZOS (probably due to the OpticStudio documentation suggesting to do so) so we should at least consider adding a note about this behaviour to the documentation. It may also be possible to automatically delete all OpticStudioSystem instances when deleting zos, but this most likely involves messing with the garbage collector, which may be dangerous.
What version of ZOSPy are you running?
1.2.0
What version of OpticStudio are you running?
23R2
Which operating system do you use?
Windows 10 Enterprise
In which environment do you use ZOSPy?
Plain Pythons scripts (not in Spyder)
Jupyter notebooks
Spyder
In which connection modes does the problem occur?
Extension mode
Standalone mode
Example code
importloggingimportzospyaszp# Initiate logging so we can follow what ZOSPy is doinglogging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
zos=zp.ZOS()
oss=zos.connect(mode="extension")
delzos# See the output below: if this doesn't print the empty set, the instance was not deletedprint(f"ZOS instances: {zp.ZOS._instances}")
When oss is deleted as well, the ZOS instance is correctly deleted:
importloggingimportzospyaszp# Initiate logging so we can follow what ZOSPy is doinglogging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
zos=zp.ZOS()
oss=zos.connect(mode="extension")
delossdelzos# See the output below: if this doesn't print the empty set, the instance was not deletedprint(f"ZOS instances: {zp.ZOS._instances}")
Where can I download the development version or when will it be released? Looking forward to your definite answer; perplexed by this question "Cannot have more than one active ZOS instance"
The development version mentioned in this issue has been released as version 1.2.0. The comment was intended to prevent confusion due to the new connect method, which was not yet available when I opened this issue. As this version has now been released, I removed these comments to prevent further confusion.
Your comment suggests to me that you are actually looking for something else. Can you please indicate what you were trying to achieve, if / how that failed, and (if applicable) what behavior you expect from ZOSPy that will make it work?
If your issue is related to #19, please comment there.
Problem
Several users of ZOSPy complained about being unable to create a new
ZOS
instance, even after deleting the existing instance usingdel zos
(being unable to create a new instance when another instance exists is by design).I looked into this and there are two main reasons for this problem:
ZOS
instance is not removed by the garbage collector after callingdel zos
.OpticStudioSystem
instances. EveryOpticStudioSystem
contains a reference to theZOS
instance that created it. As a result, there will still be some references to thisZOS
instance, and deletingzos
will not result in its removal by the garbage collector. It is therefore necessary toI am not sure if this should be considered a bug, as this is related to how Python works. Furthermore, it is not necessary to delete and recreate
ZOS
objects, as the same instance can be used to manage allOpticStudioSystem
instances. Nevertheless, users expect to be able to deleteZOS
(probably due to the OpticStudio documentation suggesting to do so) so we should at least consider adding a note about this behaviour to the documentation. It may also be possible to automatically delete allOpticStudioSystem
instances when deletingzos
, but this most likely involves messing with the garbage collector, which may be dangerous.What version of ZOSPy are you running?
1.2.0
What version of OpticStudio are you running?
23R2
Which operating system do you use?
Windows 10 Enterprise
In which environment do you use ZOSPy?
In which connection modes does the problem occur?
Example code
Output
Additional information
When
oss
is deleted as well, theZOS
instance is correctly deleted:Output:
The text was updated successfully, but these errors were encountered: