inky
inky copied to clipboard
Replace 'time.time()' with 'time.monotonic()' for timeout loops
'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.