Skip to content

Commit

Permalink
Add test and fix
Browse files Browse the repository at this point in the history
Add a test for the behavior described in issue 4092, and fix the
reference counting logic so that the reference count is decremented from
even from one to zero.  This ensures that the reference count is correct
even if the desktop instance is not design-initialized and so is not
released by Design.__exit__.
  • Loading branch information
isaacwaldron committed Jan 17, 2024
1 parent 2bb23c6 commit 0259784
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions _unittest/test_01_Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,12 @@ def test_40_get_design_settings(self, add_app):
assert "AmbRadTemp" in design_settings_dict
assert "GravityVec" in design_settings_dict
assert "GravityDir" in design_settings_dict

def test_41_desktop_reference_counting(self, desktop):
num_references = desktop._connected_app_instances
with Hfss() as hfss:
assert hfss
assert desktop._connected_app_instances == num_references + 1
hfss.set_active_design(hfss.design_name)
assert desktop._connected_app_instances == num_references + 1
assert desktop._connected_app_instances == num_references
4 changes: 2 additions & 2 deletions pyaedt/application/Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def __str__(self):
def __exit__(self, ex_type, ex_value, ex_traceback):
if ex_type:
exception_to_desktop(ex_value, ex_traceback)
if self._desktop_class._connected_app_instances > 1:
if self._desktop_class._connected_app_instances > 0:
self._desktop_class._connected_app_instances -= 1
elif self._desktop_class._initialized_from_design:
if self._desktop_class._connected_app_instances < 1 and self._desktop_class._initialized_from_design:
self.release_desktop(self.close_on_exit, self.close_on_exit)

def __enter__(self):
Expand Down

0 comments on commit 0259784

Please sign in to comment.