summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy <jimmy@spalge.com>2022-03-26 14:58:11 +1300
committerJimmy <jimmy@spalge.com>2022-03-26 16:06:42 +1300
commita546c5fcfc5b78269331cfe841eb88c30d657885 (patch)
tree0bf3206138a488bfe5f97965276df52215d5c923
parent7e3f8f5984049a2920812b2280d61bbf0f4101bf (diff)
downloadqutebrowser-a546c5fcfc5b78269331cfe841eb88c30d657885.tar.gz
qutebrowser-a546c5fcfc5b78269331cfe841eb88c30d657885.zip
Disable debugcachestats on python < 3.9
Since I added weakrefs into the cache stats debug registry thing it no longer works on python version 3.5 to 3.8, since lru_cache doesn't support weak refs for those versions. It should be possible to do some conditional stuff and get some functionality working on all supported versions but I don't think there is any great need to for a debug command. Links: https://bugs.python.org/issue14373 https://bugs.python.org/issue40504 https://github.com/qutebrowser/qutebrowser/pull/7079#issuecomment-1079539046
-rw-r--r--qutebrowser/misc/debugcachestats.py19
-rw-r--r--qutebrowser/misc/utilcmds.py6
2 files changed, 20 insertions, 5 deletions
diff --git a/qutebrowser/misc/debugcachestats.py b/qutebrowser/misc/debugcachestats.py
index 1e4139e43..4d15a6fa3 100644
--- a/qutebrowser/misc/debugcachestats.py
+++ b/qutebrowser/misc/debugcachestats.py
@@ -24,8 +24,11 @@ dependencies as possible to avoid cyclic dependencies.
"""
import weakref
+import sys
from typing import Any, Callable, List, Optional, Tuple, TypeVar
+from qutebrowser.utils import log
+
# The second element of each tuple should be a lru_cache wrapped function
_CACHE_FUNCTIONS: List[Tuple[str, Any]] = []
@@ -37,15 +40,23 @@ _T = TypeVar('_T', bound=Callable[..., Any])
def register(name: Optional[str] = None) -> Callable[[_T], _T]:
"""Register a lru_cache wrapped function for debug_cache_stats."""
def wrapper(fn: _T) -> _T:
- fn_ref = weakref.ref(fn)
- _CACHE_FUNCTIONS.append((fn.__name__ if name is None else name, fn_ref))
- return fn
+ fn_name = fn.__name__ if name is None else name
+ if sys.version_info < (3, 9):
+ log.misc.vdebug( # type: ignore[attr-defined]
+ 'debugcachestats not supported on python < 3.9, not adding \'%s\'',
+ fn_name,
+ )
+ return fn
+
+ else:
+ fn_ref = weakref.ref(fn)
+ _CACHE_FUNCTIONS.append((fn_name, fn_ref))
+ return fn
return wrapper
def debug_cache_stats() -> None:
"""Print LRU cache stats."""
- from qutebrowser.utils import log
for idx, (name, fn_ref) in reversed(list(enumerate(_CACHE_FUNCTIONS))):
fn = fn_ref()
if not fn:
diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py
index 7ba45bdc3..da774379f 100644
--- a/qutebrowser/misc/utilcmds.py
+++ b/qutebrowser/misc/utilcmds.py
@@ -23,6 +23,7 @@
import functools
import os
+import sys
import traceback
from typing import Optional
@@ -125,7 +126,10 @@ def debug_all_objects() -> None:
@cmdutils.register(debug=True)
def debug_cache_stats() -> None:
"""Print LRU cache stats."""
- debugcachestats.debug_cache_stats()
+ if sys.version_info < (3, 9):
+ message.error('debugcachestats not supported on python < 3.9')
+ else:
+ debugcachestats.debug_cache_stats()
@cmdutils.register(debug=True)