From cd80d7f20164e6ce4ce7b0b99db56bb7297c116d Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Wed, 8 Jun 2011 20:25:12 +0100 Subject: persist_data: Add back code to retry in the case of locked database errors Signed-off-by: Richard Purdie --- lib/bb/persist_data.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/bb/persist_data.py b/lib/bb/persist_data.py index 03adc7cc5..551b58a2a 100644 --- a/lib/bb/persist_data.py +++ b/lib/bb/persist_data.py @@ -55,7 +55,16 @@ class SQLTable(collections.MutableMapping): % table) def _execute(self, *query): - return self.cursor.execute(*query) + """Execute a query, waiting to acquire a lock if necessary""" + count = 0 + while True: + try: + return self.cursor.execute(*query) + except sqlite3.OperationalError as exc: + if 'database is locked' in str(exc) and count < 500: + count = count + 1 + continue + raise def __enter__(self): self.cursor.__enter__() -- cgit 1.2.3-korg