fix: reconcile cancelled sessions and resume queued native work

This commit is contained in:
阿白叔 committed 2026-11-17 08:37:23 +08:00
1 parent 845ae58690
commit 7cc65f78da
10 files changed
+637 -18

No files matched your search

+9 -2
View File
@@ -390,6 +390,13 @@ class NativeQueue:
def run(self, action, *, stop=None, waiting=None, ready=lambda: True, wait_state=None,
context=None, timeout_seconds=10):
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))
ticket = [object(), False]
acquired, notified = False, False
previous_state = None
@@ -401,7 +408,7 @@ class NativeQueue:
self.pending.append(ticket)
try:
while not acquired:
available = ready() # Call only this ticket's predicate, outside the queue lock.
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()
or context is not None and (context.stop.is_set() or context.stop_after_current.is_set())):
@@ -412,7 +419,7 @@ class NativeQueue:
self.active = acquired = True
else:
self.condition.wait(.1)
if acquired and not ready():
if acquired and not available_now():
with self.condition:
ticket[1] = self.active = acquired = False
self.condition.notify_all()