use weakref for backrefs so collection doesn't need to be garbage collected

This commit is contained in:
Damien Elmes 2020-03-03 21:25:32 +10:00
parent a8e6fbd0fd
commit ffe6ecf44c
7 changed files with 14 additions and 6 deletions

View File

@ -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 = {}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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: