fix: allow bounded full-library release scans to complete
This commit is contained in:
1 parent
edd1e088af
commit
0ee24d7beb
2 files changed
+49
-23
No files matched your search
@@ -13,8 +13,9 @@ from uuid import uuid4
|
||||
|
||||
|
||||
@contextmanager
|
||||
def hold_release_files(library, roots=None, *, saved_project=None, timeout_seconds=10, stop=None):
|
||||
def hold_release_files(library, roots=None, *, saved_project=None, timeout_seconds=None, stop=None):
|
||||
"""Only this pure probe may be terminated. stdin EOF releases its handles."""
|
||||
from .operation_queue import native_phase
|
||||
with tempfile.TemporaryDirectory(prefix='cbb-file-probe-') as folder:
|
||||
job = Path(folder)/'request.json'
|
||||
token = uuid4().hex
|
||||
@@ -27,30 +28,34 @@ def hold_release_files(library, roots=None, *, saved_project=None, timeout_secon
|
||||
stderr=subprocess.DEVNULL, creationflags=getattr(subprocess, 'CREATE_NO_WINDOW', 0))
|
||||
try:
|
||||
started = time.monotonic()
|
||||
deadline = started + max(.1, min(10, timeout_seconds))
|
||||
limit = 30 if roots is None and saved_project is None else 10
|
||||
budget = limit if timeout_seconds is None else min(limit, timeout_seconds)
|
||||
deadline = started + max(.1, budget)
|
||||
result_path = job.with_name('result.json')
|
||||
while True:
|
||||
if stop is not None and stop.is_set():
|
||||
raise InterruptedError('FILE_PROBE_CANCELLED')
|
||||
if time.monotonic() >= deadline:
|
||||
# The isolated helper has its own deadline and cancel signal.
|
||||
with native_phase(read_only=True):
|
||||
while True:
|
||||
if stop is not None and stop.is_set():
|
||||
raise InterruptedError('FILE_PROBE_CANCELLED')
|
||||
if time.monotonic() >= deadline:
|
||||
try:
|
||||
progress = json.loads(job.with_name('progress.json').read_text('utf-8'))
|
||||
except (OSError, ValueError):
|
||||
progress = {}
|
||||
stage = progress.get('stage', 'startup')
|
||||
path = progress.get('path', str(library))
|
||||
raise TimeoutError(f'FILE_PROBE_TIMEOUT: 文件占用检查超时'
|
||||
f'({time.monotonic()-started:.1f}s,{stage},{path}),未证明释放')
|
||||
try:
|
||||
progress = json.loads(job.with_name('progress.json').read_text('utf-8'))
|
||||
except (OSError, ValueError):
|
||||
progress = {}
|
||||
stage = progress.get('stage', 'startup')
|
||||
path = progress.get('path', str(library))
|
||||
raise TimeoutError(f'FILE_PROBE_TIMEOUT: 文件占用检查超时'
|
||||
f'({time.monotonic()-started:.1f}s,{stage},{path}),未证明释放')
|
||||
try:
|
||||
record = json.loads(result_path.read_text('utf-8'))
|
||||
break
|
||||
except FileNotFoundError:
|
||||
if process.poll() is not None and not result_path.exists():
|
||||
raise OSError('FILE_PROBE_UNCONFIRMED: 文件探测未返回证据') from None
|
||||
except PermissionError:
|
||||
# Windows may temporarily share-lock a newly published receipt.
|
||||
pass
|
||||
time.sleep(.02)
|
||||
record = json.loads(result_path.read_text('utf-8'))
|
||||
break
|
||||
except FileNotFoundError:
|
||||
if process.poll() is not None and not result_path.exists():
|
||||
raise OSError('FILE_PROBE_UNCONFIRMED: 文件探测未返回证据') from None
|
||||
except PermissionError:
|
||||
# Windows may temporarily share-lock a newly published receipt.
|
||||
pass
|
||||
time.sleep(.02)
|
||||
if stop is not None and stop.is_set():
|
||||
raise InterruptedError('FILE_PROBE_CANCELLED')
|
||||
if record.get('token') != token or record.get('status') != 'HELD' or process.poll() is not None:
|
||||
|
||||
Reference in new issue
Block a user