@@ -37,36 +37,39 @@ async def _get_client(self):
3737 self .logger .debug (f"Reusing client from pool | ID:{ id (client )} " )
3838 return client
3939
40+ if len (self ._active_clients ) < self .POOL_SIZE :
41+ break
42+
4043 for task in self ._active_tasks :
4144 task .cancel ()
4245
4346 self ._pool_lock .release ()
4447 await asyncio .sleep (retry_interval )
4548 await asyncio .wait_for (self ._pool_lock .acquire (), timeout = timeout - (time .time () - start_time ))
4649
47- # if "memory_required" in self.config:
48- # await self.memory_checker.check_memory(self.config["memory_required"])
49- self .logger .debug ("Creating new LLM client" )
50- client = ASRClient (
51- host = self .config ["host" ],
52- port = self .config ["port" ]
53- )
54- self ._active_clients [id (client )] = client
50+ if "memory_required" in self .config :
51+ await self .memory_checker .check_memory (self .config ["memory_required" ])
52+ self .logger .debug ("Creating new LLM client" )
53+ client = ASRClient (
54+ host = self .config ["host" ],
55+ port = self .config ["port" ]
56+ )
57+ self ._active_clients [id (client )] = client
5558
56- loop = asyncio .get_event_loop ()
57- await loop .run_in_executor (
58- None ,
59- client .setup ,
60- "whisper.setup" ,
61- {
62- "model" : self .config ["model_name" ],
63- "response_format" : "asr.utf-8" ,
64- "input" : "whisper.base64.stream" ,
65- "language" : "zh" ,
66- "enoutput" : True
67- }
68- )
69- return client
59+ loop = asyncio .get_event_loop ()
60+ await loop .run_in_executor (
61+ None ,
62+ client .setup ,
63+ "whisper.setup" ,
64+ {
65+ "model" : self .config ["model_name" ],
66+ "response_format" : "asr.utf-8" ,
67+ "input" : "whisper.base64.stream" ,
68+ "language" : "zh" ,
69+ "enoutput" : True
70+ }
71+ )
72+ return client
7073 except asyncio .TimeoutError :
7174 raise RuntimeError ("Server busy, please try again later." )
7275 finally :
0 commit comments