Skip to content
Merged
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: 6 additions & 1 deletion python/hsml/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#

import os
import weakref

from hsml import client
from hsml.core import model_api, model_registry_api, model_serving_api
Expand Down Expand Up @@ -165,6 +166,7 @@ def connect(self):
```
"""
self._connected = True
finalizer = weakref.finalize(self, self.close)
try:
# init client
if client.hopsworks.base.Client.REST_ENDPOINT not in os.environ:
Expand All @@ -185,6 +187,7 @@ def connect(self):
self._model_serving_api.load_default_configuration() # istio client, default resources,...
except (TypeError, ConnectionError):
self._connected = False
finalizer.detach()
raise
print("Connected. Call `.close()` to terminate connection gracefully.")

Expand All @@ -194,8 +197,10 @@ def close(self):
This will clean up any materialized certificates on the local file system of
external environments.

Usage is recommended but optional.
Usage is optional.
"""
if not self._connected:
return # the connection is already closed
client.stop()
self._model_api = None
self._connected = False
Expand Down