From e10dc362197d630cc16a2c48cbb4ade48d5064b5 Mon Sep 17 00:00:00 2001 From: Friedrich Lindenberg Date: Fri, 14 Jun 2013 10:33:57 +0200 Subject: [PATCH] Try to avoid some locking issues. --- dataset/persistence/database.py | 18 ++++++++++-------- dataset/persistence/table.py | 2 +- setup.py | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/dataset/persistence/database.py b/dataset/persistence/database.py index aa9569c..31c83ee 100644 --- a/dataset/persistence/database.py +++ b/dataset/persistence/database.py @@ -46,9 +46,15 @@ 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 + def _release_internal(self): + if not hasattr(self.local, 'must_release') and self.local.must_release: + self.lock.release() + self.local.must_release = False + def begin(self): """ Enter a transaction explicitly. No data will be written until the transaction has been committed. """ @@ -62,18 +68,14 @@ class Database(object): since the transaction was begun permanent. """ self.local.tx.commit() del self.local.tx - if not hasattr(self.local, 'must_release'): - self.lock.release() - del self.local.must_release + self._release_internal() def rollback(self): """ Roll back the current transaction, discarding all statements executed since the transaction was begun. """ self.local.tx.rollback() del self.local.tx - if not hasattr(self.local, 'must_release'): - self.lock.release() - del self.local.must_release + self._release_internal() @property def tables(self): @@ -83,7 +85,7 @@ class Database(object): set([u'user', u'action']) """ return list(set(self.metadata.tables.keys() + - self._tables.keys())) + self._tables.keys())) def create_table(self, table_name): """ @@ -148,7 +150,7 @@ class Database(object): return self.load_table(table_name) else: return self.create_table(table_name) - finally: + finally: self._release() def __getitem__(self, table_name): diff --git a/dataset/persistence/table.py b/dataset/persistence/table.py index cd42de6..d48a0db 100644 --- a/dataset/persistence/table.py +++ b/dataset/persistence/table.py @@ -213,7 +213,7 @@ class Table(object): if name not in self.table.columns.keys(): col = Column(name, type) col.create(self.table, - connection=self.database.engine) + connection=self.database.executable) finally: self.database._release() diff --git a/setup.py b/setup.py index 28ad7f9..cc0c74b 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='dataset', - version='0.3.5', + version='0.3.6', description="Toolkit for Python-based data processing.", long_description="", classifiers=[