fix: retry session control publication on Windows sharing locks
This commit is contained in:
1 parent
9803993d49
commit
b9193dbb21
2 files changed
+19
-4
No files matched your search
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import time
|
||||
from threading import Event, Thread
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -11,8 +12,19 @@ from .worker_monitor import WorkerMonitorError, run_monitored_process
|
||||
|
||||
def _write_control(path: Path, value: str):
|
||||
temporary = path.with_name(path.name + '.' + uuid4().hex + '.tmp')
|
||||
temporary.write_text(value, encoding='utf-8')
|
||||
temporary.replace(path)
|
||||
try:
|
||||
temporary.write_text(value, encoding='utf-8')
|
||||
deadline = time.monotonic() + 1.0
|
||||
while True:
|
||||
try:
|
||||
temporary.replace(path)
|
||||
return
|
||||
except PermissionError:
|
||||
if time.monotonic() >= deadline:
|
||||
raise
|
||||
time.sleep(.02)
|
||||
finally:
|
||||
temporary.unlink(missing_ok=True)
|
||||
|
||||
|
||||
class ProjectSessionWorker:
|
||||
|
||||
Reference in new issue
Block a user