From 6f0d305489a4add2935df4567a4a129f49269a2b Mon Sep 17 00:00:00 2001 From: wisp3rwind <17089248+wisp3rwind@users.noreply.github.com> Date: Thu, 4 May 2023 08:48:25 +0200 Subject: [PATCH] tests: more explicit sqlite3 connection close()ing --- beets/dbcore/db.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index 94396f81b..a3909cf14 100755 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -975,7 +975,11 @@ class Database: # bytestring paths here on Python 3, so we need to # provide a `str` using `py3_path`. conn = sqlite3.connect( - py3_path(self.path), timeout=self.timeout + py3_path(self.path), + timeout=self.timeout, + # We have our own same-thread checks in _connection(), but need to + # call conn.close() in _close() + check_same_thread=False, ) self.add_functions(conn) @@ -1005,7 +1009,9 @@ class Database: unusable; new connections can still be opened on demand. """ with self._shared_map_lock: - self._connections.clear() + while self._connections: + _thread_id, conn = self._connections.popitem() + conn.close() @contextlib.contextmanager def _tx_stack(self):