Bug #634165: Better dealing with a locked database in python

Patch by Christoph Holtermann:

For the second enhancement proposal i have attached a simple patch which adds
the argument ignore_lock to Session.__init__() which is passed through to
qof_session_begin.

This patch extends the function Session.__init__() with ignore_lock

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19795 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2010-11-10 19:49:21 +00:00
parent 98b42582ca
commit 76da42522e

View File

@ -63,7 +63,7 @@ class Session(GnuCashCoreClass):
Invoice..) is associated with a particular book where it is stored. Invoice..) is associated with a particular book where it is stored.
""" """
def __init__(self, book_uri=None, is_new=False): def __init__(self, book_uri=None, is_new=False, ignore_lock=False):
"""A convienent contructor that allows you to specify a book URI, """A convienent contructor that allows you to specify a book URI,
begin the session, and load the book. begin the session, and load the book.
@ -78,6 +78,8 @@ class Session(GnuCashCoreClass):
is_new is passed to qof_session_begin as the is_new is passed to qof_session_begin as the
argument create_if_nonexistent argument create_if_nonexistent
ignore_lock is passed to qof_session
This function can raise a GnuCashBackendException. If it does, This function can raise a GnuCashBackendException. If it does,
you don't need to cleanup and call end() and destroy(), that is handled you don't need to cleanup and call end() and destroy(), that is handled
for you, and the exception is raised. for you, and the exception is raised.
@ -85,7 +87,7 @@ class Session(GnuCashCoreClass):
GnuCashCoreClass.__init__(self) GnuCashCoreClass.__init__(self)
if book_uri is not None: if book_uri is not None:
try: try:
self.begin(book_uri, False, is_new) self.begin(book_uri, ignore_lock, is_new)
if not is_new: if not is_new:
self.load() self.load()
except GnuCashBackendException, backend_exception: except GnuCashBackendException, backend_exception: