diff --git a/pylib/anki/decks.py b/pylib/anki/decks.py index a149adc81..e19999cea 100644 --- a/pylib/anki/decks.py +++ b/pylib/anki/decks.py @@ -7,6 +7,7 @@ import copy import json import operator import unicodedata +import weakref from typing import Any, Dict, List, Optional, Set, Tuple, Union import anki # pylint: disable=unused-import @@ -101,7 +102,7 @@ class DeckManager: ############################################################# def __init__(self, col: anki.storage._Collection) -> None: - self.col = col + self.col = weakref.proxy(col) self.decks = {} self.dconf = {} diff --git a/pylib/anki/media.py b/pylib/anki/media.py index 1b947cd59..96ef0e846 100644 --- a/pylib/anki/media.py +++ b/pylib/anki/media.py @@ -10,6 +10,7 @@ import time import urllib.error import urllib.parse import urllib.request +import weakref from typing import Any, Callable, List, Optional, Tuple, Union import anki @@ -42,7 +43,7 @@ class MediaManager: regexps = soundRegexps + imgRegexps def __init__(self, col: anki.storage._Collection, server: bool) -> None: - self.col = col + self.col = weakref.proxy(col) if server: self._dir = None return diff --git a/pylib/anki/models.py b/pylib/anki/models.py index 858604b60..d74973142 100644 --- a/pylib/anki/models.py +++ b/pylib/anki/models.py @@ -7,6 +7,7 @@ import copy import json import re import time +import weakref from typing import Any, Callable, Dict, List, Optional, Tuple, Union import anki # pylint: disable=unused-import @@ -91,7 +92,7 @@ class ModelManager: ############################################################# def __init__(self, col: anki.storage._Collection) -> None: - self.col = col + self.col = weakref.proxy(col) self.models = {} self.changed = False diff --git a/pylib/anki/rsbackend.py b/pylib/anki/rsbackend.py index 26d0eef66..22f9e547a 100644 --- a/pylib/anki/rsbackend.py +++ b/pylib/anki/rsbackend.py @@ -176,12 +176,14 @@ def proto_progress_to_native(progress: pb.Progress) -> Progress: else: assert_impossible_literal(kind) + def _on_progress(progress_bytes: bytes) -> bool: progress = pb.Progress() progress.ParseFromString(progress_bytes) native_progress = proto_progress_to_native(progress) return hooks.bg_thread_progress_callback(True, native_progress) + class RustBackend: def __init__( self, col_path: str, media_folder_path: str, media_db_path: str, log_path: str diff --git a/pylib/anki/sched.py b/pylib/anki/sched.py index e4afefce3..9c436cc0e 100644 --- a/pylib/anki/sched.py +++ b/pylib/anki/sched.py @@ -6,6 +6,7 @@ from __future__ import annotations import itertools import random import time +import weakref from heapq import * from operator import itemgetter from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union @@ -30,7 +31,7 @@ class Scheduler: _burySiblingsOnAnswer = True def __init__(self, col: anki.storage._Collection) -> None: - self.col = col + self.col = weakref.proxy(col) self.queueLimit = 50 self.reportLimit = 1000 self.reps = 0 diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index 5307e8f90..88a8a10c8 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -7,6 +7,7 @@ import datetime import itertools import random import time +import weakref from heapq import * from operator import itemgetter @@ -37,7 +38,7 @@ class Scheduler: revCount: int def __init__(self, col: anki.storage._Collection) -> None: - self.col = col + self.col = weakref.proxy(col) self.queueLimit = 50 self.reportLimit = 1000 self.dynReportLimit = 99999 diff --git a/pylib/anki/tags.py b/pylib/anki/tags.py index cfbb9d62e..6085fa7b5 100644 --- a/pylib/anki/tags.py +++ b/pylib/anki/tags.py @@ -13,6 +13,7 @@ from __future__ import annotations import json import re +import weakref from typing import Callable, Collection, Dict, List, Optional, Tuple import anki # pylint: disable=unused-import @@ -26,7 +27,7 @@ class TagManager: ############################################################# def __init__(self, col: anki.storage._Collection) -> None: - self.col = col + self.col = weakref.proxy(col) self.tags: Dict[str, int] = {} def load(self, json_: str) -> None: