perf(asr): 优化 SSL 上下文创建,避免阻塞事件循环

- 将 SSL 上下文初始化从 __init__ 延迟到 __aenter__
- 使用 asyncio.to_thread 在线程池中执行 SSL 上下文创建
- 避免在同步构造函数中执行潜在的阻塞操作
This commit is contained in:
2026-05-01 22:40:17 +08:00
parent 2ffc20b14c
commit 10ccc01c6d
@@ -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: