python的Sqlite问题

时间:2017-08-02 09:46:17

标签: python python-2.7 sqlite python-multiprocessing

我必须一次向Sqlite数据库(4个线程)添加大量记录,但我在数据库中只有4条记录。代码正在迭代。
代码段:

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))

0 个答案:

没有答案