fix: preserve accepted native calls and explain retained queue waits
This commit is contained in:
1 parent
d0a5ce5d17
commit
78ff118f82
13 files changed
+357
-30
No files matched your search
@@ -15,9 +15,10 @@ class NativeQueue:
|
||||
def wake(self):
|
||||
with self.condition: self.condition.notify_all()
|
||||
|
||||
def run(self, action, *, stop=None, waiting=None, ready=lambda: True):
|
||||
def run(self, action, *, stop=None, waiting=None, ready=lambda: True, wait_state=None):
|
||||
ticket = object()
|
||||
acquired, notified = False, False
|
||||
previous_state = None
|
||||
with self.condition: self.pending.append((ticket, ready))
|
||||
try:
|
||||
while not acquired:
|
||||
@@ -30,10 +31,14 @@ class NativeQueue:
|
||||
self.active = acquired = True
|
||||
else:
|
||||
self.condition.wait(.1)
|
||||
if not acquired and not notified and waiting is not None:
|
||||
notified = True
|
||||
try: waiting()
|
||||
except Exception: pass
|
||||
if not acquired and waiting is not None:
|
||||
try:
|
||||
current_state = wait_state() if wait_state is not None else None
|
||||
if not notified or current_state != previous_state:
|
||||
waiting()
|
||||
notified, previous_state = True, current_state
|
||||
except Exception:
|
||||
pass
|
||||
if stop is not None and stop.is_set():
|
||||
raise QueueCancelled('已取消排队,未启动原生操作。')
|
||||
return action()
|
||||
|
||||
Reference in new issue
Block a user