feat: 任务可调并发、可批量操作,导航栏可收缩

This commit is contained in:
2026-10-25 08:22:32 +08:00
parent 6a230ee8d4
commit 5f3bb312b3
10 changed files with 375 additions and 56 deletions
+15 -7
View File
@@ -475,6 +475,7 @@ class NqiClient:
progress,
skip: set[str] | None = None,
run_event: asyncio.Event | None = None,
halt_event: asyncio.Event | None = None,
*,
grid_size: str = "GRID20",
failed_tiles: list | None = None,
@@ -519,7 +520,7 @@ class NqiClient:
try:
await progress(len(seen))
while not cancel_event.is_set() and (pending or inflight):
if not await _wait_turn(cancel_event, run_event):
if not await _wait_turn(cancel_event, run_event, halt_event):
break
while pending and len(inflight) < 3 and not cancel_event.is_set():
if run_event is not None and not run_event.is_set():
@@ -566,7 +567,7 @@ class NqiClient:
fresh.append(grid_id)
await progress(len(seen))
for grid_id in fresh:
if not await _wait_turn(cancel_event, run_event):
if not await _wait_turn(cancel_event, run_event, halt_event):
break
yield grid_id
if cancel_event.is_set():
@@ -739,18 +740,25 @@ async def _interruptible_sleep(seconds: float, cancel_event: asyncio.Event, run_
return not cancel_event.is_set()
async def _wait_turn(cancel_event: asyncio.Event, run_event: asyncio.Event | None) -> bool:
"""暂停时停住。返回 False 表示任务已停止。"""
async def _wait_turn(
cancel_event: asyncio.Event,
run_event: asyncio.Event | None,
halt_event: asyncio.Event | None = None,
) -> bool:
"""暂停时停住。返回 False 表示停止或要按新的并发重开。"""
def halted() -> bool:
return halt_event is not None and halt_event.is_set()
if run_event is None:
return not cancel_event.is_set()
return not cancel_event.is_set() and not halted()
while not run_event.is_set():
if cancel_event.is_set():
if cancel_event.is_set() or halted():
return False
try:
await asyncio.wait_for(run_event.wait(), timeout=0.3)
except asyncio.TimeoutError:
continue
return not cancel_event.is_set()
return not cancel_event.is_set() and not halted()
def _public_user(data: dict) -> dict: