From 99b26c1fdc55e19a1e01e59f546089d0a91fc7a4 Mon Sep 17 00:00:00 2001 From: "jinli.yl" Date: Thu, 12 Feb 2026 21:02:05 +0800 Subject: [PATCH] feat(context): reinitialize thread pool and Ray when starting service context --- reme/core/context/service_context.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/reme/core/context/service_context.py b/reme/core/context/service_context.py index ced8fa5f..2de4b026 100644 --- a/reme/core/context/service_context.py +++ b/reme/core/context/service_context.py @@ -169,6 +169,19 @@ class ServiceContext(BaseContext): async def start(self): """Start the service context by initializing all configured components.""" + # Recreate thread pool if it was shut down + if self.thread_pool is None or self.thread_pool._shutdown: + self.thread_pool = ThreadPoolExecutor( + max_workers=self.service_config.thread_pool_max_workers, + ) + + # Re-initialize Ray if it was shut down + if self.service_config.ray_max_workers > 1: + import ray + + if not ray.is_initialized(): + ray.init(num_cpus=self.service_config.ray_max_workers) + for name, config in self.service_config.llms.items(): if config.backend not in R.llms: logger.warning(f"LLM backend {config.backend} is not supported.")