From 21a07727c1cf23b0502e9cf0b56e28d0581fbc3e Mon Sep 17 00:00:00 2001 From: Stavros Sachtouris <saxtouri@admin.grnet.gr> Date: Fri, 26 Jun 2015 12:24:06 +0300 Subject: [PATCH] Retry initializing database when it is locked --- agkyra/cli.py | 4 ---- agkyra/protocol.py | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/agkyra/cli.py b/agkyra/cli.py index 5f55e67..3c7bf08 100644 --- a/agkyra/cli.py +++ b/agkyra/cli.py @@ -306,7 +306,3 @@ class AgkyraCLI(cmd.Cmd): else: sys.stderr.write('Not running\n') sys.stderr.flush() - - def do_florist(self, line): - """RUN FLORIST, RUN!""" - sys.stderr.write('RUN: %s\n' % STATUS) diff --git a/agkyra/protocol.py b/agkyra/protocol.py index 16ce932..946be59 100644 --- a/agkyra/protocol.py +++ b/agkyra/protocol.py @@ -38,6 +38,7 @@ with open(os.path.join(CURPATH, 'ui_common.json')) as f: UI_COMMON = json.load(f) STATUS = UI_COMMON['STATUS'] + def retry_on_locked_db(method, *args, **kwargs): """If DB is locked, wait and try again""" wait = kwargs.get('wait', 0.2) @@ -68,7 +69,7 @@ class SessionHelper(object): LOG.debug('Connect to db') self.db = sqlite3.connect(self.session_db) - self._init_db_relation() + retry_on_locked_db(self._init_db_relation) def _init_db_relation(self): """Create the session relation""" -- GitLab