Retry transient Windows sharing conflicts when publishing private CAD state
This commit is contained in:
1 parent
980198a987
commit
7610a0fd86
2 files changed
+54
-2
No files matched your search
@@ -31,6 +31,21 @@ def _child_environment(environment):
|
||||
return environment
|
||||
|
||||
|
||||
def _replace_record(temporary, target):
|
||||
# Windows readers can temporarily deny delete access to the old JSON.
|
||||
# Keep the complete old record until replacement succeeds, with a finite
|
||||
# retry budget so persistent permissions failures still reach the caller.
|
||||
deadline = time.monotonic() + 1.0
|
||||
while True:
|
||||
try:
|
||||
temporary.replace(target)
|
||||
return
|
||||
except PermissionError:
|
||||
if time.monotonic() >= deadline:
|
||||
raise
|
||||
time.sleep(0.02)
|
||||
|
||||
|
||||
def _designer_executable():
|
||||
import winreg
|
||||
with winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, r'Viewdraw.Application\CLSID') as key:
|
||||
@@ -65,13 +80,13 @@ class IsolatedCadSession:
|
||||
target = self.root / 'private-desktop.json'
|
||||
temporary = target.with_suffix('.tmp')
|
||||
temporary.write_text(json.dumps(self.record, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
temporary.replace(target)
|
||||
_replace_record(temporary, target)
|
||||
history = self.root / 'private-desktop-sessions'
|
||||
history.mkdir(exist_ok=True)
|
||||
archived = history / (self.token + '.json')
|
||||
pending = archived.with_suffix('.tmp')
|
||||
pending.write_text(json.dumps(self.record, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
pending.replace(archived)
|
||||
_replace_record(pending, archived)
|
||||
|
||||
def __enter__(self):
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user