From 5f96bb4a76b6e9144fe447e33f322eb7f3af9681 Mon Sep 17 00:00:00 2001 From: Kieran Black Date: Sun, 25 Feb 2024 10:12:45 -0600 Subject: [PATCH] use monotonic clock for time deltas in progress manager --- qt/aqt/progress.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qt/aqt/progress.py b/qt/aqt/progress.py index a7673b30ae2..ba27cb10ab7 100644 --- a/qt/aqt/progress.py +++ b/qt/aqt/progress.py @@ -163,7 +163,7 @@ def start( self._counter = min self._min = min self._max = max - self._firstTime = time.time() + self._firstTime = time.monotonic() self._show_timer = QTimer(self.mw) self._show_timer.setSingleShot(True) self._show_timer.start(immediate and 100 or 600) @@ -206,7 +206,7 @@ def update( maybeShow: bool = True, max: int | None = None, ) -> None: - # print self._min, self._counter, self._max, label, time.time() - self._lastTime + # print self._min, self._counter, self._max, label, time.monotonic() - self._lastTime if not self.mw.inMainThread(): print("progress.update() called on wrong thread") return @@ -257,7 +257,7 @@ def do_window_cleanup(future: Future | None = None): # to expose ourselves to the possibility of something showing the window in the # meantime if self._shown: - elapsed_time = time.time() - self._shown + elapsed_time = time.monotonic() - self._shown if (time_to_wait := 0.5 - elapsed_time) > 0: self.mw.taskman.run_in_background( lambda time_to_wait=time_to_wait: time.sleep(time_to_wait), @@ -280,12 +280,12 @@ def _maybeShow(self) -> None: return if self._shown: return - delta = time.time() - self._firstTime + delta = time.monotonic() - self._firstTime if delta > 0.5: self._showWin() def _showWin(self) -> None: - self._shown = time.time() + self._shown = time.monotonic() self._win.show() def _closeWin(self) -> None: