我编写了Python(3.7)脚本来与通过串行端口连接的设备进行通信。当它发送消息或读取响应时,它还将所有内容记录在文件中,并带有日期时间。
对于串行通信和文件打开/写入,每个异常均得到明确处理。
此脚本应在Windows 10上运行数周,问题是它在几分钟或几小时后随机暂停,直到按下Enter键。
我可以直接访问计算机,因此没有ssh问题或类似问题。
电脑没有停止,它一直在运行。
该脚本不需要控制台输入。如果与串行端口通信时发生超时,则结束。
脚本暂停时,没有人使用计算机,因此不会突出显示文本或进行其他类型的交互。
该脚本可以从暂停位置完美恢复,没有任何问题。
在相同的时间后,脚本并不总是冻结/暂停。
库和Tk代码
import sys
import os
from datetime import datetime
import serial # pySerial 3.4
import atexit
import time
from tkinter import Tk
import requests
# Other constants and variables
# Init Tk
root = Tk()
root.withdraw() # don't show the GUI window
root.after(TIME_UNTIL_END, end_countdown, root) # call end_countdown() after TIME_UNTIL_END
root.after(0, tick_operation, tick_time, root) # call tick_operation() right away and pass time until next call
root.mainloop()
tick_operation(tick_time)
通过串行端口发送消息并读取响应,然后在tick_time之后再次调用自身。
我想可能是代码方面的唯一可能原因是Tk。
最后,没有错误消息。我希望脚本能够继续运行而不会暂停。另外,除了此脚本外,还有另一个正在运行,并且从未停止过。
关于起因的任何线索以及如何解决?
非常感谢!