From d1a43c74db54ebc196cc1b63fe22d6be2fea66a5 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 15:05:27 +0800 Subject: [PATCH] Add logging for service cleanup hooks in new-style BentoML services (#5171) * Add logging for new-style service shutdown hooks in app.py Co-Authored-By: frost@bentoml.com * refactor: improve service cleanup hook logging Co-Authored-By: frost@bentoml.com * feat: add service instance cleanup completion logging Co-Authored-By: frost@bentoml.com * refactor: move final cleanup log after proxy closure Co-Authored-By: frost@bentoml.com --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: frost@bentoml.com --- src/_bentoml_impl/server/app.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/_bentoml_impl/server/app.py b/src/_bentoml_impl/server/app.py index e3017f11e90..338da86faa3 100644 --- a/src/_bentoml_impl/server/app.py +++ b/src/_bentoml_impl/server/app.py @@ -320,16 +320,21 @@ async def destroy_instance(self, _: Starlette) -> None: # Call on_shutdown hook with optional ctx or context parameter for name, member in vars(self.service.inner).items(): if callable(member) and getattr(member, "__bentoml_shutdown_hook__", False): + logger.info("Running cleanup hook: %s", name) result = getattr( self._service_instance, name )() # call the bound method if inspect.isawaitable(result): await result + logger.info("Completed async cleanup hook: %s", name) + else: + logger.info("Completed cleanup hook: %s", name) await cleanup() own_proxy = getattr(self._service_instance, "__self_proxy__", None) if isinstance(own_proxy, RemoteProxy): await own_proxy.close() + logger.info("Service instance cleanup finalized") self._service_instance = None set_current_service(None) await self._result_store.__aexit__(None, None, None)