File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -226,6 +226,7 @@ def __init__(
226
226
self .engines_id = [str (uuid .uuid4 ()) for i in range (0 , len (urls ))]
227
227
self .added_timestamp = int (time .time ())
228
228
self .unhealthy_endpoint_hashes = []
229
+ self ._running = True
229
230
if static_backend_health_checks :
230
231
self .start_health_check_task ()
231
232
self .prefill_model_labels = prefill_model_labels
@@ -250,10 +251,10 @@ def get_unhealthy_endpoint_hashes(self) -> list[str]:
250
251
return unhealthy_endpoints
251
252
252
253
async def check_model_health (self ):
253
- while True :
254
+ while self . _running :
254
255
try :
255
256
self .unhealthy_endpoint_hashes = self .get_unhealthy_endpoint_hashes ()
256
- time .sleep (60 )
257
+ await asyncio .sleep (60 ) # Use async sleep instead of time.sleep
257
258
except Exception as e :
258
259
logger .error (e )
259
260
@@ -340,6 +341,17 @@ async def initialize_client_sessions(self) -> None:
340
341
timeout = aiohttp .ClientTimeout (total = None ),
341
342
)
342
343
344
+ def close (self ):
345
+ """
346
+ Close the service discovery module and clean up health check resources.
347
+ """
348
+ self ._running = False
349
+ if hasattr (self , "loop" ) and self .loop is not None :
350
+ self .loop .call_soon_threadsafe (self .loop .stop )
351
+ if hasattr (self , "thread" ) and self .thread is not None :
352
+ self .thread .join (timeout = 5.0 )
353
+ self .loop .close ()
354
+
343
355
344
356
class K8sPodIPServiceDiscovery (ServiceDiscovery ):
345
357
def __init__ (
You can’t perform that action at this time.
0 commit comments