Spaces:
Running
Running
nacho commited on
Commit ·
3ee386a
1
Parent(s): 3cb96d8
fix: prelogin capped at 3 rounds + revert aggressive check_login_state
Browse files- deepseek_browser.py +0 -9
- main.py +23 -15
deepseek_browser.py
CHANGED
|
@@ -94,15 +94,6 @@ class DeepSeekBrowser:
|
|
| 94 |
|
| 95 |
async def _check_login_state(self):
|
| 96 |
current_url = self.page.url
|
| 97 |
-
try:
|
| 98 |
-
await self.page.wait_for_selector("textarea", timeout=10000)
|
| 99 |
-
self._logged_in = True
|
| 100 |
-
self._ready = True
|
| 101 |
-
if self._logged_in:
|
| 102 |
-
await self._check_mute()
|
| 103 |
-
return
|
| 104 |
-
except Exception:
|
| 105 |
-
pass
|
| 106 |
if "/sign_in" in current_url:
|
| 107 |
await self._auto_login()
|
| 108 |
else:
|
|
|
|
| 94 |
|
| 95 |
async def _check_login_state(self):
|
| 96 |
current_url = self.page.url
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
if "/sign_in" in current_url:
|
| 98 |
await self._auto_login()
|
| 99 |
else:
|
main.py
CHANGED
|
@@ -382,7 +382,7 @@ async def import_accounts(request: Request, admin_key: str = Header(...)):
|
|
| 382 |
|
| 383 |
# 异步触发新导入账号的并行预登录
|
| 384 |
if new_accounts:
|
| 385 |
-
asyncio.create_task(_prelogin_loop(sem_size=8,
|
| 386 |
|
| 387 |
return {"success": True, "imported": imported, "total": len(manager.accounts)}
|
| 388 |
|
|
@@ -747,25 +747,27 @@ async def startup():
|
|
| 747 |
asyncio.create_task(_prelogin_all())
|
| 748 |
|
| 749 |
|
| 750 |
-
async def _prelogin_loop(sem_size=8,
|
| 751 |
-
"""通用预登录
|
| 752 |
|
| 753 |
参数:
|
| 754 |
-
sem_size:
|
| 755 |
-
|
| 756 |
"""
|
| 757 |
total = len(manager.accounts)
|
| 758 |
-
|
|
|
|
|
|
|
| 759 |
pending = [
|
| 760 |
(email, acc) for email, acc in manager.accounts.items()
|
| 761 |
if not acc.logged_in and acc.error_count < 5
|
| 762 |
]
|
| 763 |
if not pending:
|
| 764 |
-
logger.info("[prelogin] All accounts ready
|
| 765 |
return
|
| 766 |
|
| 767 |
-
logger.info("[prelogin] %d/%d accounts pending
|
| 768 |
-
len(pending), total, sem_size)
|
| 769 |
sem = asyncio.Semaphore(sem_size)
|
| 770 |
|
| 771 |
async def _login_one(email, account):
|
|
@@ -788,17 +790,23 @@ async def _prelogin_loop(sem_size=8, retry_delay=180):
|
|
| 788 |
if not a.logged_in and a.error_count < 5
|
| 789 |
)
|
| 790 |
if still_pending == 0:
|
| 791 |
-
logger.info("[prelogin] All done")
|
| 792 |
return
|
| 793 |
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 797 |
|
| 798 |
|
| 799 |
async def _prelogin_all():
|
| 800 |
-
"""启动时
|
| 801 |
-
await _prelogin_loop(sem_size=8,
|
| 802 |
|
| 803 |
|
| 804 |
def main():
|
|
|
|
| 382 |
|
| 383 |
# 异步触发新导入账号的并行预登录
|
| 384 |
if new_accounts:
|
| 385 |
+
asyncio.create_task(_prelogin_loop(sem_size=8, max_rounds=3))
|
| 386 |
|
| 387 |
return {"success": True, "imported": imported, "total": len(manager.accounts)}
|
| 388 |
|
|
|
|
| 747 |
asyncio.create_task(_prelogin_all())
|
| 748 |
|
| 749 |
|
| 750 |
+
async def _prelogin_loop(sem_size=8, max_rounds=3):
|
| 751 |
+
"""通用预登录:并行登录,每轮失败的等更久后重试,最多 max_rounds 轮。
|
| 752 |
|
| 753 |
参数:
|
| 754 |
+
sem_size: 最大同时登录数(默认 8)
|
| 755 |
+
max_rounds: 最多重试轮数(默认 3),每轮间隔 3min → 10min → 30min
|
| 756 |
"""
|
| 757 |
total = len(manager.accounts)
|
| 758 |
+
delays = [180, 600, 1800] # 3min, 10min, 30min
|
| 759 |
+
|
| 760 |
+
for round_idx in range(max_rounds):
|
| 761 |
pending = [
|
| 762 |
(email, acc) for email, acc in manager.accounts.items()
|
| 763 |
if not acc.logged_in and acc.error_count < 5
|
| 764 |
]
|
| 765 |
if not pending:
|
| 766 |
+
logger.info("[prelogin] All accounts ready")
|
| 767 |
return
|
| 768 |
|
| 769 |
+
logger.info("[prelogin round %d/%d] %d/%d accounts pending (concurrency=%d)...",
|
| 770 |
+
round_idx + 1, max_rounds, len(pending), total, sem_size)
|
| 771 |
sem = asyncio.Semaphore(sem_size)
|
| 772 |
|
| 773 |
async def _login_one(email, account):
|
|
|
|
| 790 |
if not a.logged_in and a.error_count < 5
|
| 791 |
)
|
| 792 |
if still_pending == 0:
|
| 793 |
+
logger.info("[prelogin] All done after round %d", round_idx + 1)
|
| 794 |
return
|
| 795 |
|
| 796 |
+
if round_idx < max_rounds - 1:
|
| 797 |
+
delay = delays[min(round_idx, len(delays) - 1)]
|
| 798 |
+
logger.info("[prelogin] %d accounts still pending, waiting %ds before round %d...",
|
| 799 |
+
still_pending, delay, round_idx + 2)
|
| 800 |
+
await asyncio.sleep(delay)
|
| 801 |
+
|
| 802 |
+
remaining = sum(1 for a in manager.accounts.values() if not a.logged_in)
|
| 803 |
+
logger.info("[prelogin] Giving up after %d rounds. %d/%d accounts online, %d failed",
|
| 804 |
+
max_rounds, total - remaining, total, remaining)
|
| 805 |
|
| 806 |
|
| 807 |
async def _prelogin_all():
|
| 808 |
+
"""启动时预登录:同时 8 个,最多 3 轮,失败不再无限重试。"""
|
| 809 |
+
await _prelogin_loop(sem_size=8, max_rounds=3)
|
| 810 |
|
| 811 |
|
| 812 |
def main():
|