Skip to content

Commit 60dd883

Browse files
cj-zhangJoseph Zhang
and
Joseph Zhang
authored
Cache client as instance attribute in property@ decorator. (aws#1668)
* Remove property@ decorator from ABC definition. * Cache client as instance attribute in @Property. * Fix flake8 issue. --------- Co-authored-by: Joseph Zhang <[email protected]>
1 parent db42dc5 commit 60dd883

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/sagemaker/serve/spec/inference_base.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818
class CustomOrchestrator(ABC):
1919
"""Templated class to standardize sync entrypoint-based inference scripts"""
2020

21+
def __init__(self):
22+
self._client = None
23+
2124
@property
2225
def client(self):
2326
"""Boto3 SageMaker runtime client to use with custom orchestrator"""
24-
from boto3 import Session
27+
if not hasattr(self, "_client"):
28+
from boto3 import Session
29+
30+
self._client = Session().client("sagemaker-runtime")
2531

26-
return Session().client("sagemaker-runtime")
32+
return self._client
2733

2834
@abstractmethod
2935
def handle(self, data, context=None):

0 commit comments

Comments
 (0)