Skip to content

Commit

Permalink
use monotonic clock for time deltas in progress manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranlblack committed Feb 25, 2024
1 parent f3c0787 commit 5f96bb4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions qt/aqt/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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:
Expand Down

0 comments on commit 5f96bb4

Please sign in to comment.