in template/v3/dirs/etc/sagemaker-inference-server/tornado_server/server.py [0:0]
def _load_inference_handler(self) -> callable:
"""Load the handler function from the inference script."""
logger.info("Loading inference handler...")
inference_module_name, handle_name = self._environment.code.split(".")
if inference_module_name and handle_name:
inference_module_file = f"{inference_module_name}.py"
module_spec = importlib.util.spec_from_file_location(
inference_module_file, str(self._path_to_inference_code.joinpath(inference_module_file))
)
if module_spec:
sys.path.insert(0, str(self._path_to_inference_code.resolve()))
module = importlib.util.module_from_spec(module_spec)
module_spec.loader.exec_module(module)
if hasattr(module, handle_name):
handler = getattr(module, handle_name)
else:
raise InferenceCodeLoadException(
f"Handler `{handle_name}` could not be found in module `{inference_module_file}`"
)
logger.debug(f"Loaded handler `{handle_name}` from module `{inference_module_name}`")
return handler
else:
raise InferenceCodeLoadException(
f"Inference code could not be found at `{str(self._path_to_inference_code.joinpath(inference_module_file))}`"
)
raise InferenceCodeLoadException(
f"Inference code expected in the format of `<module>.<handler>` but was provided as {self._environment.code}"
)