Try to avoid some locking issues.

This commit is contained in:
Friedrich Lindenberg 2013-06-14 10:33:57 +02:00
parent 57c37ac453
commit e10dc36219
3 changed files with 12 additions and 10 deletions

View File

@ -46,9 +46,15 @@ class Database(object):
def _release(self): def _release(self):
if not hasattr(self.local, 'tx'): if not hasattr(self.local, 'tx'):
self.lock.release() self.lock.release()
self.local.must_release = False
else: else:
self.local.must_release = True 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): def begin(self):
""" Enter a transaction explicitly. No data will be written """ Enter a transaction explicitly. No data will be written
until the transaction has been committed. """ until the transaction has been committed. """
@ -62,18 +68,14 @@ class Database(object):
since the transaction was begun permanent. """ since the transaction was begun permanent. """
self.local.tx.commit() self.local.tx.commit()
del self.local.tx del self.local.tx
if not hasattr(self.local, 'must_release'): self._release_internal()
self.lock.release()
del self.local.must_release
def rollback(self): def rollback(self):
""" Roll back the current transaction, discarding all statements """ Roll back the current transaction, discarding all statements
executed since the transaction was begun. """ executed since the transaction was begun. """
self.local.tx.rollback() self.local.tx.rollback()
del self.local.tx del self.local.tx
if not hasattr(self.local, 'must_release'): self._release_internal()
self.lock.release()
del self.local.must_release
@property @property
def tables(self): def tables(self):
@ -83,7 +85,7 @@ class Database(object):
set([u'user', u'action']) set([u'user', u'action'])
""" """
return list(set(self.metadata.tables.keys() + return list(set(self.metadata.tables.keys() +
self._tables.keys())) self._tables.keys()))
def create_table(self, table_name): def create_table(self, table_name):
""" """
@ -148,7 +150,7 @@ class Database(object):
return self.load_table(table_name) return self.load_table(table_name)
else: else:
return self.create_table(table_name) return self.create_table(table_name)
finally: finally:
self._release() self._release()
def __getitem__(self, table_name): def __getitem__(self, table_name):

View File

@ -213,7 +213,7 @@ class Table(object):
if name not in self.table.columns.keys(): if name not in self.table.columns.keys():
col = Column(name, type) col = Column(name, type)
col.create(self.table, col.create(self.table,
connection=self.database.engine) connection=self.database.executable)
finally: finally:
self.database._release() self.database._release()

View File

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup( setup(
name='dataset', name='dataset',
version='0.3.5', version='0.3.6',
description="Toolkit for Python-based data processing.", description="Toolkit for Python-based data processing.",
long_description="", long_description="",
classifiers=[ classifiers=[