fix: resume verification after an owned session releases

This commit is contained in:
阿白叔 committed 2026-11-23 18:28:40 +08:00
1 parent 6d2b6de027
commit 31a93cd313
9 files changed
+293 -34

No files matched your search

+22 -5
View File
@@ -13,10 +13,18 @@ class QueueCancelled(RuntimeError):
class QueueUnavailable(RuntimeError):
"""Admission failed before action dispatch; this task created no native session."""
def __init__(self, library):
def __init__(self, library, sessions=(), *, timed_out=False):
self.library = str(library)
super().__init__('NATIVE_SESSION_PENDING: '+self.library+
' 的已登记会话仍在运行或初始化,当前项未启动。')
self.sessions = tuple(sessions)
self.timed_out = timed_out
details = []
for session in self.sessions:
block = session.get('block') or '当前库'
resources = '、'.join(map(str, session.get('blocked_resources') or ()))
details.append(' / '.join(filter(None, (block, session.get('operation_id'),
resources, session.get('path')))))
message = f'NATIVE_SESSION_PENDING: {self.library} 的已登记会话待释放,当前项未启动。'
super().__init__(message + (' ' + ';'.join(details) if details else ''))
class TaskHandoff(QueueCancelled):
@@ -417,8 +425,10 @@ class NativeQueue:
for context in contexts)
def run(self, action, *, stop=None, waiting=None, ready=lambda: True, wait_state=None,
context=None, timeout_seconds=10, skip_unavailable=False):
context=None, timeout_seconds=10, skip_unavailable=False, wait_for_release_seconds=None):
release_deadline = None
def available_now():
nonlocal release_deadline
if not ready():
return False
if context is None:
@@ -426,8 +436,15 @@ class NativeQueue:
from .session_record import _live_library_available
for path in (context.library, *context.aliases):
if not _live_library_available(path):
if skip_unavailable:
if skip_unavailable and wait_for_release_seconds is None:
raise QueueUnavailable(path)
if wait_for_release_seconds is not None:
now = time.monotonic()
if release_deadline is None:
release_deadline = now + wait_for_release_seconds
if now >= release_deadline:
from .session_record import retained_session_states
raise QueueUnavailable(path, retained_session_states(path), timed_out=True)
return False
return True
ticket = [object(), False]