From 1cf2cfd6e3358462f1dd64751e9ea01d9907052e Mon Sep 17 00:00:00 2001 From: liuwei Date: Fri, 17 Apr 2026 10:28:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmd2img=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=E5=B9=B6=E5=8F=91=E5=8D=95=E4=BE=8B=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E9=A2=84=E7=83=AD=E5=8F=8C=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/markdown_to_image.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/markdown_to_image.py b/utils/markdown_to_image.py index dfd6e12..5b1de08 100644 --- a/utils/markdown_to_image.py +++ b/utils/markdown_to_image.py @@ -689,6 +689,7 @@ class _PersistentBrowser: _BROWSER_MANAGER: Optional[_PersistentBrowser] = None _MD2IMG_RUNTIME = None +_MD2IMG_RUNTIME_LOCK = threading.Lock() class _Md2ImgRuntime: @@ -754,8 +755,12 @@ class _Md2ImgRuntime: def _get_md2img_runtime() -> _Md2ImgRuntime: global _MD2IMG_RUNTIME + # 并发首次访问时要加锁,避免创建出多个 runtime 实例, + # 进而出现“专用运行时已启动”日志重复与多线程并存问题。 if _MD2IMG_RUNTIME is None: - _MD2IMG_RUNTIME = _Md2ImgRuntime() + with _MD2IMG_RUNTIME_LOCK: + if _MD2IMG_RUNTIME is None: + _MD2IMG_RUNTIME = _Md2ImgRuntime() return _MD2IMG_RUNTIME