fix: skip unavailable items and isolate batch failures

This commit is contained in:
阿白叔 committed 2026-11-19 10:06:04 +08:00
1 parent 07eab61695
commit 3bde847ff7
13 files changed
+592 -36

No files matched your search

+18 -2
View File
@@ -11,6 +11,14 @@ class QueueCancelled(RuntimeError):
pass
class QueueUnavailable(RuntimeError):
"""Admission failed before action dispatch; this task created no native session."""
def __init__(self, library):
self.library = str(library)
super().__init__('NATIVE_SESSION_PENDING: '+self.library+
' 的已登记会话仍在运行或初始化,当前项未启动。')
class TaskHandoff(QueueCancelled):
"""The call is still observable; this is never a release receipt."""
def __init__(self, context, *, cancelled=False, result=None):
@@ -409,14 +417,19 @@ 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):
context=None, timeout_seconds=10, skip_unavailable=False):
def available_now():
if not ready():
return False
if context is None:
return True # Explicit recovery controls must still reach their retained clients.
from .session_record import _live_library_available
return all(_live_library_available(path) for path in (context.library, *context.aliases))
for path in (context.library, *context.aliases):
if not _live_library_available(path):
if skip_unavailable:
raise QueueUnavailable(path)
return False
return True
ticket = [object(), False]
acquired, notified = False, False
previous_state = None
@@ -428,6 +441,9 @@ class NativeQueue:
self.pending.append(ticket)
try:
while not acquired:
if (self.closed or stop is not None and stop.is_set()
or context is not None and (context.stop.is_set() or context.stop_after_current.is_set())):
raise QueueCancelled('已取消排队,未启动原生操作。')
available = available_now() # Cached predicates only, outside the queue lock.
with self.condition:
if (self.closed or stop is not None and stop.is_set()