I wrote a Python (3.7) script to communicate with a device connected through serial port. When it sends a message or reads a response, it also logs everything on a file, with date time.
Every exception is explicitly handled for both serial communication and file opening/writing.
This script should run for many weeks on Windows 10, the problem is that it randomly pause after minutes or hours until enter key is pressed.
I have direct access to the computer, so no ssh problems or similar.
Computer doesn't stop, it's always running.
The script doesn't require console inputs. If there is a timeout while communicating with serial port, it ends.
No one was using the computer when the script paused, so no text highlighting or other kinds of interactions.
The script resumes perfectly from where it paused without any problem.
The script doesn't always freeze/pause after the same amount of time.
Libraries and Tk code
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)
sends a message through serial port and reads a response then calls itself again after tick_time.
I guess the only possible cause for it, code side, could be Tk.
At the end, no error messages. I would expect for the script to keep running without pausing. Also, alongside this script, there was another one running, and it never stopped.
Any clues on the cause and how to solve it?
Many thanks!