inky icon indicating copy to clipboard operation
inky copied to clipboard

Replace 'time.time()' with 'time.monotonic()' for timeout loops

Open canton7 opened this issue 3 months ago • 0 comments

'time.time()' uses the system clock, which can jump forwards and backwards, e.g. because the device syncs with a time server. 'time.monotonic()' is stable and will not jump.

My specific problem is that I have a picture frame which powers on every so often, fetches another image to display, shows it, and powers off again. It doesn't keep time when powered off (so powers on with the clock in the past), then it syncs with an NTP server at some point shortly after power-on, and the clock jumps forwards. However, this often happens inside the busy polling loop, which means that the loop exits straight away with a timeout. This means that we don't want for the image to be fully displayed before returning.

canton7 avatar Nov 12 '25 09:11 canton7