Skip to content

Commit

Permalink
use finalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
hpohekar committed Apr 19, 2024
1 parent 92e96d0 commit 682f82d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/ansys/fluent/core/fluent_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import socket
import subprocess
import threading
from typing import Callable, List, Optional, Tuple, Union
from typing import Any, Callable, List, Optional, Tuple, Union
import warnings
import weakref

Expand All @@ -20,6 +20,7 @@
from ansys.fluent.core.services import service_creator
from ansys.fluent.core.services.scheme_eval import SchemeEvalService
from ansys.fluent.core.utils.execution import timeout_exec, timeout_loop
from ansys.fluent.core.utils.file_transfer_service import RemoteFileTransferStrategy
from ansys.platform.instancemanagement import Instance
import docker

Expand Down Expand Up @@ -303,6 +304,7 @@ def __init__(
channel: Optional[grpc.Channel] = None,
cleanup_on_exit: bool = True,
remote_instance: Optional[Instance] = None,
file_transfer_service: Optional[Any] = None,
slurm_job_id: Optional[str] = None,
inside_container: Optional[bool] = None,
):
Expand Down Expand Up @@ -333,6 +335,8 @@ def __init__(
The corresponding remote instance when Fluent is launched through
PyPIM. This instance will be deleted when calling
``Session.exit()``.
file_transfer_service : optional
File transfer service. Uploads/downloads files to/from the server.
slurm_job_id: bool, optional
Job ID of a Fluent session running within a Slurm environment.
inside_container: bool, optional
Expand Down Expand Up @@ -411,6 +415,8 @@ def __init__(

self._remote_instance = remote_instance

self._file_transfer_service = file_transfer_service

self._exit_event = threading.Event()

# session.exit() is handled in the daemon thread (MonitorThread) which ensures
Expand All @@ -430,6 +436,7 @@ def __init__(
self._connection_interface,
self.finalizer_cbs,
self._remote_instance,
self._file_transfer_service,
self._exit_event,
)
FluentConnection._monitor_thread.cbs.append(self._finalizer)
Expand Down Expand Up @@ -697,6 +704,7 @@ def _exit(
connection_interface,
finalizer_cbs,
remote_instance,
file_transfer_service,
exit_event,
) -> None:
logger.debug("FluentConnection exit method called.")
Expand All @@ -714,4 +722,9 @@ def _exit(
if remote_instance:
remote_instance.delete()

if file_transfer_service and isinstance(
file_transfer_service, RemoteFileTransferStrategy
):
file_transfer_service.container.stop()

exit_event.set()
2 changes: 0 additions & 2 deletions src/ansys/fluent/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,11 @@ def exit(self, **kwargs) -> None:
"""Exit session."""
logger.debug("session.exit() called")
self._fluent_connection.exit(**kwargs)
self._file_transfer_service.exit()

def force_exit(self) -> None:
"""Immediately terminate the Fluent session, losing unsaved progress and
data."""
self._fluent_connection.force_exit()
self._file_transfer_service.exit()

def file_exists_on_remote(self, file_name: str) -> bool:
"""Check if remote file exists.
Expand Down

0 comments on commit 682f82d

Please sign in to comment.