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

fix: Session was not garbage collected after settings access #3327

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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