Skip to content

Commit

Permalink
fix: Session was not garbage collected after settings access (#3327)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkundu1 authored Sep 30, 2024
1 parent bc5ce13 commit b188862
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/ansys/fluent/core/session_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,16 @@ def workflow(self):
)
return self._workflow

def _interrupt(self, command):
@classmethod
def _interrupt(cls, command):
interruptible_commands = [
"solution/run-calculation/iterate",
"solution/run-calculation/calculate",
"solution/run-calculation/dual-time-iterate",
]
if pyfluent.SUPPORT_SOLVER_INTERRUPT:
if command.path in interruptible_commands:
self.settings.solution.run_calculation.interrupt()
command._root.solution.run_calculation.interrupt()

@property
def settings(self):
Expand All @@ -230,7 +231,7 @@ def settings(self):
self._settings_root = flobject.get_root(
flproxy=self._settings_service,
version=self._version,
interrupt=self._interrupt,
interrupt=Solver._interrupt,
file_transfer_service=self._file_transfer_service,
scheme_eval=self.scheme_eval.scheme_eval,
)
Expand Down
13 changes: 7 additions & 6 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,12 @@ def __init__(self, name: str | None = None, parent=None):
self._setattr("_name", name)
self._setattr("_child_alias_objs", {})

def _root(self, obj):
if obj._parent is None:
return obj
@property
def _root(self):
if self._parent is None:
return self
else:
return self._root(obj._parent)
return self._parent._root

def set_flproxy(self, flproxy):
"""Set flproxy object."""
Expand Down Expand Up @@ -1758,7 +1759,7 @@ def __call__(self, **kwds):
try:
return self.execute_command(**kwds)
except KeyboardInterrupt:
self._root(self)._on_interrupt(self)
self._root._on_interrupt(self)
raise KeyboardInterrupt


Expand Down Expand Up @@ -1789,7 +1790,7 @@ def __call__(self, *args, **kwds):
try:
return self.execute_command(*args, **kwds)
except KeyboardInterrupt:
self._root(self)._on_interrupt(self)
self._root._on_interrupt(self)
raise KeyboardInterrupt


Expand Down
2 changes: 2 additions & 0 deletions tests/test_fluent_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def print_transcript(transcript):
def test_server_exits_when_session_goes_out_of_scope() -> None:
def f():
session = pyfluent.launch_fluent()
session.settings
_fluent_host_pid = session.connection_properties.fluent_host_pid
_cortex_host = session.connection_properties.cortex_host
_inside_container = session.connection_properties.inside_container
Expand All @@ -88,6 +89,7 @@ def f():
def test_server_does_not_exit_when_session_goes_out_of_scope() -> None:
def f():
session = pyfluent.launch_fluent(cleanup_on_exit=False)
session.settings
_fluent_host_pid = session.connection_properties.fluent_host_pid
_cortex_host = session.connection_properties.cortex_host
_inside_container = session.connection_properties.inside_container
Expand Down

0 comments on commit b188862

Please sign in to comment.