修复md2img运行时并发单例问题,避免预热双启动日志
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user