Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging for service cleanup hooks in new-style BentoML services #5171

Merged
merged 4 commits into from
Jan 7, 2025
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
5 changes: 5 additions & 0 deletions src/_bentoml_impl/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading