diff --git a/beets/library.py b/beets/library.py index dc9020d63..e9ac0b7e1 100644 --- a/beets/library.py +++ b/beets/library.py @@ -959,6 +959,8 @@ class Library(BaseLibrary): return it.next() except StopIteration: return None + finally: + it.close() def get_album(self, item_or_id): """Given an album ID or an item associated with an album, @@ -976,8 +978,10 @@ class Library(BaseLibrary): 'SELECT * FROM albums WHERE id=?', (album_id,) ) - record = c.fetchone() - c.close() + try: + record = c.fetchone() + finally: + c.close() if record: return Album(self, dict(record)) diff --git a/beetsplug/bpd/__init__.py b/beetsplug/bpd/__init__.py index 77db61a05..9d3d4baf8 100644 --- a/beetsplug/bpd/__init__.py +++ b/beetsplug/bpd/__init__.py @@ -889,8 +889,9 @@ class Server(BaseServer): statement = 'SELECT COUNT(DISTINCT artist), ' \ 'COUNT(DISTINCT album) FROM items' - c = self.lib.conn.cursor() - result = c.execute(statement).fetchone() + c = self.lib.conn.execute(statement) + result = c.fetchone() + c.close() artists, albums = result[0], result[1] yield (u'artists: ' + unicode(artists),