From 10ccc01c6dd8e69e05c2fe2cf0ff757059a68e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E5=A2=A8?= Date: Fri, 1 May 2026 22:40:17 +0800 Subject: [PATCH] =?UTF-8?q?perf(asr):=20=E4=BC=98=E5=8C=96=20SSL=20?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E5=88=9B=E5=BB=BA=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E9=98=BB=E5=A1=9E=E4=BA=8B=E4=BB=B6=E5=BE=AA=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 SSL 上下文初始化从 __init__ 延迟到 __aenter__ - 使用 asyncio.to_thread 在线程池中执行 SSL 上下文创建 - 避免在同步构造函数中执行潜在的阻塞操作 --- custom_components/hass_stt_doubao/doubaoime_asr/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_components/hass_stt_doubao/doubaoime_asr/client.py b/custom_components/hass_stt_doubao/doubaoime_asr/client.py index a985820..8c441ca 100644 --- a/custom_components/hass_stt_doubao/doubaoime_asr/client.py +++ b/custom_components/hass_stt_doubao/doubaoime_asr/client.py @@ -35,9 +35,10 @@ class DoubaoASR: def __init__(self, config: Optional[ASRConfig] = None): self.config = config self._encoder = AudioEncoder(self.config) - self._ssl_context = ssl.create_default_context() + self._ssl_context: Optional[ssl.SSLContext] = None async def __aenter__(self) -> DoubaoASR: + self._ssl_context = await asyncio.to_thread(ssl.create_default_context) return self async def __aexit__(self, exc_type, exc_val, exc_tb) -> None: