Try to avoid some locking issues.
This commit is contained in:
parent
57c37ac453
commit
e10dc36219
@ -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):
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user