This commit is contained in:
2026-01-27 09:25:04 +08:00
parent 935531955f
commit e14aabd0e2
3 changed files with 113 additions and 93 deletions

28
run.py
View File

@@ -773,6 +773,8 @@ def process_accounts_concurrent(
if max_workers is None:
max_workers = CONCURRENT_WORKERS
stagger_delay = 2.0 # 线程错开启动间隔 (秒)
# 过滤已完成的账号
pending_accounts = [acc for acc in accounts if acc.get("status") != "completed"]
@@ -784,7 +786,7 @@ def process_accounts_concurrent(
total = len(pending_accounts)
actual_workers = min(max_workers, total)
log.section(f"并发处理 {total} 个账号 (并发数: {actual_workers})")
log.section(f"并发处理 {total} 个账号 (并发数: {actual_workers}, 间隔: {stagger_delay}s)")
# 启动进度跟踪
progress_start(team_name, total, team_index, teams_total, include_owner)
@@ -793,16 +795,26 @@ def process_accounts_concurrent(
completed_count = 0
with ThreadPoolExecutor(max_workers=actual_workers) as executor:
# 提交所有任务
future_to_account = {
executor.submit(
# 错开提交任务,每个任务间隔 stagger_delay 秒
future_to_account = {}
for i, account in enumerate(pending_accounts):
if _shutdown_requested:
break
worker_id = i % actual_workers + 1
log.info(f"[Worker-{worker_id}] 启动任务: {account['email']}", icon="start")
future = executor.submit(
_process_single_account_worker,
account,
team_name,
i % actual_workers + 1
): account
for i, account in enumerate(pending_accounts)
}
worker_id
)
future_to_account[future] = account
# 错开启动,最后一个不需要等待
if i < len(pending_accounts) - 1:
time.sleep(stagger_delay)
# 收集结果
for future in as_completed(future_to_account):