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: