From 420edc45e00a235962e75767edb3570fbb31d9d7 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Tue, 17 Jan 2012 16:06:39 +0100 Subject: [PATCH] Make db in the format metadata proxy classes into a weak reference to avoid garbage collection problems. One consequence: if the db has gone away before the metadata is used, then the format information will appear to be empty. --- src/calibre/library/database2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 9297918373..5fe010f829 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en' The database used to store ebook metadata ''' import os, sys, shutil, cStringIO, glob, time, functools, traceback, re, \ - json, uuid, hashlib, copy + json, uuid, hashlib, copy, weakref from collections import defaultdict, MutableMapping, MutableSequence import threading, random from itertools import repeat @@ -84,7 +84,7 @@ class Tag(object): class FormatMetadata(MutableMapping): # {{{ def __init__(self, db, id_, formats): - self.db = db + self.dbwref = weakref.ref(db) self.id_ = id_ self.formats = formats self._must_do = True @@ -94,7 +94,7 @@ class FormatMetadata(MutableMapping): # {{{ if self._must_do: for f in self.formats: try: - self.values[f] = self.db.format_metadata(self.id_, f) + self.values[f] = self.dbwref().format_metadata(self.id_, f) except: pass self._must_do = False