From 7fa056bfe2e4d8f802d76bb5f5d2431fd24f44dd Mon Sep 17 00:00:00 2001 From: Di Wu Date: Tue, 26 Jan 2016 14:38:27 +0800 Subject: [PATCH] Release all the locks acquired by transaction on commit/rollback --- dataset/persistence/database.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dataset/persistence/database.py b/dataset/persistence/database.py index 12ea7e3..cfc8d47 100644 --- a/dataset/persistence/database.py +++ b/dataset/persistence/database.py @@ -70,22 +70,22 @@ class Database(object): def _release(self): if not hasattr(self.local, 'tx'): self.lock.release() - self.local.must_release = False else: - self.local.must_release = True + self.local.lock_count[-1] += 1 def _release_internal(self): - if getattr(self.local, 'must_release', None): + for index in range(self.local.lock_count[-1]): self.lock.release() - self.local.must_release = False + del self.local.lock_count[-1] def _dispose_transaction(self): + self._release_internal() self.local.tx.remove(self.local.tx[-1]) if not self.local.tx: del self.local.tx + del self.local.lock_count self.local.connection.close() del self.local.connection - self._release_internal() def begin(self): """ Enter a transaction explicitly. No data will be written @@ -97,7 +97,9 @@ class Database(object): self.local.connection = self.engine.connect() if not hasattr(self.local, 'tx'): self.local.tx = [] + self.local.lock_count = [] self.local.tx.append(self.local.connection.begin()) + self.local.lock_count.append(0) def commit(self): """ Commit the current transaction, making all statements executed