WeChatRobot icon indicating copy to clipboard operation
WeChatRobot copied to clipboard

[🐛BUG] 运行一段时间后,不接收消息了

Open mugbya opened this issue 1 year ago • 1 comments

描述这个 bug 对 bug 作一个清晰简明的描述:

  • 想一直运行,根据接收到的消息 自动回复消息
  • 运行一段时间后,不接受消息了

使用环境(请补全下列信息):

  • 操作系统:windows server 2022 datacenter (阿里的云电脑)
  • 操作系统版本:64 位
  • Python 版本: 3.11.0

屏幕截图 image

运行一段时候后,不打印这个日志了

    def enableReceivingMsg(self) -> None:
        def innerProcessMsg(wcf: Wcf):
            while wcf.is_receiving_msg():
                now_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
                print(f"{now_time}【等待消息】************************")
                try:
                    msg = wcf.get_msg()
                    if msg.roomid and msg.roomid not in self.config.GROUPS:
                        self.all_room.update({msg.roomid: "未知"})
                        with open("room/all_room.json", "w") as f:
                            f.write(json.dumps(self.all_room))
                        return
                    self.LOG.info(f"msg:roomid: {msg.roomid}, sender: {msg.sender}, content: {msg.content}")

                    flag = self.baseFunc.manage_command(msg, self)  # 首先执行管理指令
                    self.LOG.info(f"【管理指令】是否是管理执行指令 {flag}")
                    if not flag:
                        self.processMsg(msg)
                    # self.processMsg(msg)
                except Empty:
                    now_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
                    print(f"{now_time}【空消息】!!!!!!!!!!!!!! ")
                    continue  # Empty message
                except Exception as e:
                    traceback.print_exc()
                    self.LOG.error(f"Receiving message error: {e}")

        self.wcf.enable_receiving_msg()
        Thread(target=innerProcessMsg, name="GetMessage", args=(self.wcf,), daemon=True).start()

最开始就发现这个问题,然后在群里也有其他人遇到,群友他自己 print 打印日志后就咩有这个问题,但是我依旧存在这个问题

然后我就想看看运行的多线程情况,如下图

image

图上半截是正常运行的,下半截是不接受消息时的,线程丢失了

mugbya avatar Feb 28 '24 09:02 mugbya

可以在while结束之后加一行日志,看看是不是退出接收消息了

lich0821 avatar Mar 02 '24 08:03 lich0821