From 487e073378cab63469d86995d865915fb8a48496 Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Wed, 23 Jul 2025 18:16:16 -0700 Subject: [PATCH] library client fix since we need a runloop for stack construction which can create forever running background threads --- llama_stack/distribution/library_client.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/llama_stack/distribution/library_client.py b/llama_stack/distribution/library_client.py index 5dc0078d4..ef47eb31b 100644 --- a/llama_stack/distribution/library_client.py +++ b/llama_stack/distribution/library_client.py @@ -161,7 +161,13 @@ class LlamaStackAsLibraryClient(LlamaStackClient): if not self.skip_logger_removal: self._remove_root_logger_handlers() - return self.loop.run_until_complete(self.async_client.initialize()) + # use a new event loop to avoid interfering with the main event loop + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + try: + return loop.run_until_complete(self.async_client.initialize()) + finally: + asyncio.set_event_loop(None) def _remove_root_logger_handlers(self): """