Pyrogram "sqlite3.OperationalError: database is locked". How to assure messages will be delivered?

114 Views Asked by At

I'm frequently facing issues when Pyrogram session's sqlite database is locked by various reasons, which is very annoying. It's crucial to make sure that all messages will be delivered to both sides and not lost. How it's supposed to make it safe?

For example, function to send messages

async def send_tg(chatid, message):
    lock = asyncio.Lock()
    await lock.acquire()
    try:
        try:
            await app.start()
        except ConnectionError:
            pass
        out = await app.send_message(chatid, message)
        return out
    except FloodWait as e:
        await asyncio.sleep(e.value)
    except Exception as e:
        logger.error('error to send out')
    finally:
        lock.release()

There is FloodWait exception which will send message later after delay. Is there such option for other cases or should I rerun function recursively until it's done (it feels not right)?

0

There are 0 best solutions below