- Flask 控制台:Cliproxy 巡检、批量补号、流水线、运行日志 - codex_stats_oauth_dir 支持统计 Cliproxy auth 目录 - 忽略 accounts/oauth、.venv、本地 DB/日志与 new.py Made-with: Cursor
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""调用现有 run 模块执行批量注册(写入 cpa_id / cpa_code)"""
|
||
from __future__ import annotations
|
||
|
||
import os
|
||
import sys
|
||
import threading
|
||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||
from typing import Callable, Optional
|
||
|
||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||
if ROOT not in sys.path:
|
||
sys.path.insert(0, ROOT)
|
||
|
||
from register import RegisterConfig
|
||
|
||
import run as run_module
|
||
|
||
|
||
def run_batch(
|
||
*,
|
||
count: int,
|
||
threads: int,
|
||
proxy: str,
|
||
skip_oauth: bool,
|
||
cpa_id: int,
|
||
cpa_code: str,
|
||
on_progress: Optional[Callable[[int, int], None]] = None,
|
||
) -> tuple[int, int]:
|
||
"""
|
||
执行 count 次注册,返回 (success, failed)。
|
||
on_progress(done, total) 每完成 1 个账号回调一次(并行时顺序不定)。
|
||
"""
|
||
run_module._counter["success"] = 0
|
||
run_module._counter["failed"] = 0
|
||
run_module.set_register_context(cpa_id=cpa_id, cpa_code=cpa_code)
|
||
try:
|
||
config = RegisterConfig(proxy=proxy or "")
|
||
th = max(1, min(int(threads), int(count)))
|
||
prog_lock = threading.Lock()
|
||
completed = {"n": 0}
|
||
|
||
def one(i: int) -> None:
|
||
run_module._do_one(i, config, proxy or "", skip_oauth)
|
||
if on_progress:
|
||
with prog_lock:
|
||
completed["n"] += 1
|
||
on_progress(completed["n"], count)
|
||
|
||
if th <= 1:
|
||
for i in range(1, count + 1):
|
||
one(i)
|
||
else:
|
||
with ThreadPoolExecutor(max_workers=th) as ex:
|
||
futs = {ex.submit(one, i): i for i in range(1, count + 1)}
|
||
for fut in as_completed(futs):
|
||
fut.result()
|
||
|
||
return run_module._counter["success"], run_module._counter["failed"]
|
||
finally:
|
||
run_module.clear_register_context()
|