From 6b1348236de409cfc632a3d14984bbf41e620279 Mon Sep 17 00:00:00 2001 From: Joscha Date: Fri, 3 Aug 2018 19:47:11 +0000 Subject: [PATCH] Retry transaction until it works --- yaboli/database.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/yaboli/database.py b/yaboli/database.py index e80d8cd..7428be9 100644 --- a/yaboli/database.py +++ b/yaboli/database.py @@ -1,16 +1,23 @@ import asyncio +import logging import sqlite3 from .utils import * +logger = logging.getLogger(__name__) __all__ = ["Database", "operation"] def operation(func): async def wrapper(self, *args, **kwargs): async with self as db: - return await asyncify(func, self, db, *args, **kwargs) + while True: + try: + return await asyncify(func, self, db, *args, **kwargs) + except sqlite3.OperationalError as e: + logger.warn(f"Operational error encountered: {e}") + await asyncio.sleep(5) return wrapper class Database: