From 969c96d2913ba87118ec0d34b9ac92aa5ed47ee9 Mon Sep 17 00:00:00 2001 From: hkyc Date: Thu, 22 May 2025 23:04:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9API=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E6=94=AF=E6=8C=81=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=88=B0=E8=AE=BE=E5=AE=9A=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThreadManagerWithPyno.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/ThreadManagerWithPyno.py b/ThreadManagerWithPyno.py index 472a83d..ed7844b 100644 --- a/ThreadManagerWithPyno.py +++ b/ThreadManagerWithPyno.py @@ -191,18 +191,28 @@ class GUIThreadManagerWithPyno(ThreadManagerWithPyno): try: if self.email_source == "api": - # 使用API获取单个邮箱 - self.gui.update_status("系统消息", "正在从API获取邮箱...") - email_data = self.get_email_from_api() - if not email_data: - self.gui.update_status("API错误", "无法从API获取邮箱", result="失败") - return - - # 处理单个邮箱,不使用线程池 - if email_data['email'] not in self.completed_tasks: - self.process_email(email_data) - else: - self.gui.update_status(email_data['email'], "邮箱已处理过,跳过", result="跳过") + # 使用API模式,循环获取邮箱直到达到设定数量 + with ThreadPoolExecutor(max_workers=1) as self.executor: # 使用单线程处理 + # 循环注册,直到达到设定数量 + while self._running and (self.reg_count == 0 or self.processed_count < self.reg_count): + self.gui.update_status("系统消息", f"正在从API获取邮箱({self.processed_count+1}/{self.reg_count})...") + + # 每次只获取一个邮箱 + email_data = self.get_email_from_api() + if not email_data: + self.gui.update_status("API错误", "无法从API获取邮箱", result="失败") + break + + # 处理单个邮箱,依然使用线程池但限制为1个线程 + if email_data['email'] not in self.completed_tasks: + # 提交任务并等待完成 + future = self.executor.submit(self.process_email, email_data) + future.result() # 等待当前注册完成 + else: + self.gui.update_status(email_data['email'], "邮箱已处理过,跳过", result="跳过") + + # 每次处理完一个邮箱后,暂停一下避免请求过快 + time.sleep(2) else: # 使用本地文件获取邮箱 with open(self.email_file, 'r', encoding='utf-8') as file: