1111from grpc_health .v1 import health_pb2 , health_pb2_grpc
1212
1313from ansys .geometry .core .connection .defaults import DEFAULT_HOST , DEFAULT_PORT , MAX_MESSAGE_LENGTH
14+ from ansys .geometry .core .connection .localinstance import LocalDockerInstance
1415from ansys .geometry .core .logger import LOG as logger
1516from ansys .geometry .core .logger import PyGeometryCustomAdapter
1617from ansys .geometry .core .typing import Real
@@ -73,6 +74,11 @@ class GrpcClient:
7374 is launched through PyPIM. This instance is deleted when calling the
7475 :func:`GrpcClient.close <ansys.geometry.core.client.GrpcClient.close >`
7576 method.
77+ local_instance : LocalDockerInstance, default: None
78+ Corresponding local instance when the Geometry service is launched through
79+ the ``launch_local_modeler()`` interface. This instance will be deleted
80+ when the :func:`GrpcClient.close <ansys.geometry.core.client.GrpcClient.close >`
81+ method is called.
7682 timeout : real, default: 60
7783 Timeout in seconds to achieve the connection.
7884 logging_level : int, default: INFO
@@ -88,13 +94,15 @@ def __init__(
8894 port : Union [str , int ] = DEFAULT_PORT ,
8995 channel : Optional [grpc .Channel ] = None ,
9096 remote_instance : Optional ["Instance" ] = None ,
97+ local_instance : Optional [LocalDockerInstance ] = None ,
9198 timeout : Optional [Real ] = 60 ,
9299 logging_level : Optional [int ] = logging .INFO ,
93100 logging_file : Optional [Union [Path , str ]] = None ,
94101 ):
95102 """Initialize the ``GrpcClient`` object."""
96103 self ._closed = False
97104 self ._remote_instance = remote_instance
105+ self ._local_instance = local_instance
98106 if channel :
99107 # Used for PyPIM when directly providing a channel
100108 self ._channel = channel
@@ -162,10 +170,18 @@ def close(self):
162170 Notes
163171 -----
164172 If an instance of the Geometry service was started using
165- PyPIM, this instance is deleted.
173+ PyPIM, this instance is deleted. Furthermore, if a local instance
174+ of the Geometry Service was started, it will be stopped.
166175 """
167176 if self ._remote_instance :
168177 self ._remote_instance .delete () # pragma: no cover
178+ if self ._local_instance :
179+ if not self ._local_instance .existed_previously :
180+ self ._local_instance .container .stop ()
181+ else :
182+ self .log .warning (
183+ "Geometry Service will not be shutdown since it was already running..."
184+ )
169185 self ._closed = True
170186 self ._channel .close ()
171187
0 commit comments