'Complete a transaction. This must be the most recently
entered but not yet exited transaction. If it is the last active
transaction, the database updates are committed.'

def __exit__(self, exc_type, exc_value, traceback):

    with self.db._tx_stack() as stack:
        assert (stack.pop() is self)
        empty = (not stack)
    if empty:
        self.db._connection().commit()
        self.db._db_lock.release()
