Skip to content

Commit

Permalink
Check all timers for early triggering
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Compiler committed May 7, 2024
1 parent c48e3bc commit 01cc3df
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions qutebrowser/utils/usertypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import html
import operator
import enum
import time
import dataclasses
from typing import Optional, Sequence, TypeVar, Union

Expand Down Expand Up @@ -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:
Expand All @@ -452,13 +455,25 @@ def __init__(self, parent: QObject = None, name: str = None) -> None:
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')
super().setInterval(msec)

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)
Expand Down

0 comments on commit 01cc3df

Please sign in to comment.