summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2024-05-07 10:39:05 +0200
committerFlorian Bruhin <me@the-compiler.org>2024-05-07 10:39:05 +0200
commit01cc3dfc30dbdad081dfe8fd08d592a885574ee1 (patch)
tree104b5ce404ed31d700e954568186dab1bf715e54
parentc48e3bce36bd70df2ac33c7afffd1a3a882e177f (diff)
downloadqutebrowser-01cc3dfc30dbdad081dfe8fd08d592a885574ee1.tar.gz
qutebrowser-01cc3dfc30dbdad081dfe8fd08d592a885574ee1.zip
Check all timers for early triggering
-rw-r--r--qutebrowser/utils/usertypes.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py
index 95b1f3a01..102f57725 100644
--- a/qutebrowser/utils/usertypes.py
+++ b/qutebrowser/utils/usertypes.py
@@ -7,6 +7,7 @@
import html
import operator
import enum
+import time
import dataclasses
from typing import Optional, Sequence, TypeVar, Union
@@ -443,6 +444,8 @@ class Timer(QTimer):
def __init__(self, parent: QObject = None, name: str = None) -> None:
super().__init__(parent)
+ self._start_time = None
+ self.timeout.connect(self._check_timeout_validity)
if name is None:
self._name = "unnamed"
else:
@@ -452,6 +455,17 @@ class Timer(QTimer):
def __repr__(self) -> str:
return utils.get_repr(self, name=self._name)
+ @pyqtSlot()
+ def _check_timeout_validity(self) -> None:
+ if self._start_time is None:
+ # manual emission?
+ return
+ elapsed = time.monotonic() - self._start_time
+ if elapsed < self.interval() / 1000 / 2:
+ log.misc.warning(
+ f"Timer {self._name} (id {self.timerId()} triggered too early: "
+ f"interval {self.interval()} but only {elapsed:.3f}s passed")
+
def setInterval(self, msec: int) -> None:
"""Extend setInterval to check for overflows."""
qtutils.check_overflow(msec, 'int')
@@ -459,6 +473,7 @@ class Timer(QTimer):
def start(self, msec: int = None) -> None:
"""Extend start to check for overflows."""
+ self._start_time = time.monotonic()
if msec is not None:
qtutils.check_overflow(msec, 'int')
super().start(msec)