Skip to content

Commit c5e65f3

Browse files
committed
refactor: 移除 _prefetch_api_dates 内重复 import,补充并发注释
1 parent e084e13 commit c5e65f3

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

quantclass_sync_internal/orchestrator.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,6 @@ def _prefetch_api_dates(
903903
已在缓存中且未过期的产品跳过。失败的产品静默跳过,
904904
Plan 阶段会回退到逐产品 HTTP 查询。
905905
"""
906-
import threading
907-
from concurrent.futures import as_completed as _as_completed
908-
909906
# 1. 读现有缓存,筛出需要查询的产品
910907
existing_cache = load_api_latest_dates(log_dir)
911908
now = datetime.now()
@@ -935,7 +932,8 @@ def _prefetch_api_dates(
935932
f"[预取] 并发查询 {len(uncached)}/{len(products)} 个产品",
936933
event="PREFETCH", decision="fetching",
937934
)
938-
fetched: Dict[str, str] = {}
935+
fetched: Dict[str, str] = {} # 写入仅在主线程的 as_completed 循环内,无并发写入
936+
# abort_event 只能拦截尚未开始的 worker,已在执行的请求会自然完成或超时
939937
abort_event = threading.Event()
940938
t_start = time.time()
941939

@@ -958,7 +956,7 @@ def _fetch_one(product: str) -> Tuple[str, Optional[str]]:
958956
executor = ThreadPoolExecutor(max_workers=effective_workers)
959957
try:
960958
futures = {executor.submit(_fetch_one, p): p for p in uncached}
961-
for future in _as_completed(futures, timeout=30):
959+
for future in as_completed(futures, timeout=30):
962960
try:
963961
product, date_str = future.result()
964962
if date_str:

0 commit comments

Comments
 (0)