Skip to content

Commit e8017a6

Browse files
RobPasMuepyansys-ci-botpre-commit-ci[bot]
authored
feat: ensure GrpcClient class closure upon deletion (#1417)
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9016890 commit e8017a6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

doc/changelog.d/1417.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ensure GrpcClient class closure upon deletion

src/ansys/geometry/core/connection/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# SOFTWARE.
2222
"""Module providing a wrapped abstraction of the gRPC stubs."""
2323

24+
import atexit
2425
import logging
2526
from pathlib import Path
2627
import time
@@ -198,6 +199,10 @@ def __init__(
198199
LOG.warning("The backend version is only available after 24.1 version.")
199200
self._backend_version = semver.Version(24, 1, 0)
200201

202+
# Register the close method to be called at exit - irrespectively of
203+
# the user calling it or not...
204+
atexit.register(self.close)
205+
201206
@property
202207
def backend_type(self) -> BackendType:
203208
"""Backend type.
@@ -285,6 +290,10 @@ def close(self):
285290
deleted. Furthermore, if a local Docker instance
286291
of the Geometry service was started, it is stopped.
287292
"""
293+
if self._closed is True: # pragma: no cover
294+
self.log.debug("Connection is already closed. Ignoring request.")
295+
return
296+
288297
if self._remote_instance:
289298
self._remote_instance.delete() # pragma: no cover
290299
elif self._docker_instance:

0 commit comments

Comments
 (0)