0

I must add a lot of records to Sqlite database(4 threads) in one time but I have only 4 records in database. Code is iterating correctly.
Code snippet:

def inserter(filename):
    count = len(open(filename, 'rU').readlines())
    print str(count) + " " + filename
    for counti in range(count):
        conn = sqlite3.connect('passes.db')
        c = conn.cursor()
        m = hashlib.sha256()
        x = linecache.getline(filename, counti)
        print x + filename
        m.update(x)
        hashe = m.hexdigest()
        x = str(x)
        c.execute("INSERT INTO `passes`(`hashed`,`pass`) VALUES (?,?)", (hashe, x))
    conn.commit()
    conn.close()
    iter = ["aaa","aab","aac","aad"]
    for it in iter:
        p = multiprocessing.Process(target=inserter, args=(it,))
        p.start()
        p.join()
        print("process with id %s for file %s started" % (str(os.getpid()), it))
  • Can you edit your question to be more clear on exactly what your problem is? Saying `I have problem with sqlite` doesn't help anyone – Joshua Duxbury Aug 02 '17 at 09:53
  • 1
    You realise that `sqlite3` only supports having one process write at the same time, right? So what you're attempting to do isn't actually possible anyway. – Jon Clements Aug 02 '17 at 10:11
  • Ok thanks. So it isin't possible. –  Aug 02 '17 at 10:15
  • Relevant [sqlite3-and-multiprocessing](https://stackoverflow.com/questions/6969820/sqlite3-and-multiprocessing) – stovfl Aug 02 '17 at 13:30

0 Answers0