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):
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):

View File

@ -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()

View File

@ -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=[