R
R
Roman Burch2022-04-03 20:03:57
Python
Roman Burch, 2022-04-03 20:03:57

How to create a queue in Sqlite python3?

Wrote a bot that writes data to the database. Faced the following problem:
When 2 or more people turn on the bot at the same time, because sqlite does not like multi-threading, the bot simply turns off.

import sqlite3
import threading

_____________________________________

 def add(self, user_id, zero_or_one):
        try:
            self.lock.acquire(True)
            self.cursor.execute("UPDATE driver SET reg = ? WHERE user_id = ?", (zero_or_one, user_id))
            return self.conn.commit()
        finally:
            self.lock.release()


When I did this, the bot stopped turning off, but stopped working with other people.
For example, the two of us pressed a button, and only the one who pressed it first would write to the database, and nothing would happen to the second.

Tell me please. How to solve this problem? Or how to create a queue? I read about some multithread flags, but I did not understand at all where and how to enable them.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
This_is_MonoliT, 2022-04-03
@This_is_MonoliT

Read the thread documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question