I would like to make a program with multiple threads. In each thread should be a database INSERT.
EDIT
But now I get the same error after a time
My code:
import threading, sqlite3
class myThread(threading.Thread):
def __init__(self, pn, icm):
threading.Thread.__init__(self)
self.pn = pn
self.icm = icm
def run(self):
con = sqlite3.connect("DB.db", check_same_thread=False)
cursor = con.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS test(pn VARCHAR(100), icm VARCHAR(100))")
cursor.execute("INSERT INTO test VALUES('"+self.pn+"', '"+self.icm+"')")
con.commit()
con.close()
for i in range(0, 300):
myThread("ABCDEFG", "1234546").start()
I get the ERROR:
sqlite3.OperationalError: database is locked
Thank you, Jay
con.close(). That is why it cannot write / execute query on your database. You need to reconnect, usually withsqlite3.connect().