mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 19:09:41 +08:00
Merge pull request #1818 from dajiaohuang/fix/settings-lock-path
fix(settings): normalize Windows lock path aliases
This commit is contained in:
@@ -62,7 +62,16 @@ def _settings_lock(path: Path) -> threading.Lock:
|
||||
multi-user deployment each account has its own ``interface.json``; making
|
||||
them contend would serialise unrelated users' preference writes.
|
||||
"""
|
||||
key = str(path.resolve() if path.is_absolute() else path)
|
||||
# Resolve the directory only: resolving the file can open it on Windows
|
||||
# before its lock is acquired, preventing another writer from replacing it.
|
||||
key = os.path.normcase(str(path.parent.resolve() / path.name))
|
||||
# Windows may return an extended path while a directory is being created.
|
||||
# Both spellings must identify the same lock.
|
||||
if os.name == "nt":
|
||||
if key.startswith("\\\\?\\unc\\"):
|
||||
key = "\\\\" + key[8:]
|
||||
elif key.startswith("\\\\?\\"):
|
||||
key = key[4:]
|
||||
with _LOCKS_GUARD:
|
||||
lock = _LOCKS.get(key)
|
||||
if lock is None:
|
||||
|
||||
@@ -623,8 +623,8 @@ def test_concurrent_preference_writes_do_not_lose_updates(isolated_settings: Pat
|
||||
Unlocked, twelve concurrent writers left two of their fields on disk — the
|
||||
rest were overwritten by whichever writer had read an older snapshot.
|
||||
"""
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import json as json_module
|
||||
import threading
|
||||
|
||||
from deeptutor.services.settings.interface_settings import (
|
||||
_interface_settings_file,
|
||||
@@ -635,11 +635,8 @@ def test_concurrent_preference_writes_do_not_lose_updates(isolated_settings: Pat
|
||||
for _ in range(20):
|
||||
set_ui_setting(f"probe_{index}", index)
|
||||
|
||||
threads = [threading.Thread(target=writer, args=(i,)) for i in range(12)]
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
with ThreadPoolExecutor(max_workers=12) as executor:
|
||||
list(executor.map(writer, range(12)))
|
||||
|
||||
stored = json_module.loads(_interface_settings_file().read_text(encoding="utf-8"))
|
||||
assert {f"probe_{i}" for i in range(12)} <= set(stored)
|
||||
|
||||
Reference in New Issue
Block a user