From 94a096b7b6333d6076c1b133b3abf3b84b371e9b Mon Sep 17 00:00:00 2001 From: noName Date: Sun, 23 Oct 2022 22:20:33 +0200 Subject: [PATCH] fix rare crash related to time shift which might cause negative sleep time --- tools/rpi/hoymiles/__main__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/rpi/hoymiles/__main__.py b/tools/rpi/hoymiles/__main__.py index 2bd8b43d..0b558073 100644 --- a/tools/rpi/hoymiles/__main__.py +++ b/tools/rpi/hoymiles/__main__.py @@ -322,8 +322,10 @@ if __name__ == '__main__': print('', end='', flush=True) - if loop_interval > 0 and (time.time() - t_loop_start) < loop_interval: - time.sleep(loop_interval - (time.time() - t_loop_start)) + time_to_sleep = loop_interval - (time.time() - t_loop_start) + + if loop_interval > 0 and time_to_sleep > 0: + time.sleep(time_to_sleep) except KeyboardInterrupt: sys.exit()