无法插入 Sqlite3 数据库

Can't INSERT into Sqlite3 database

我非常绝望,因为我尽我所能让它工作但没有成功...我创建了一个池来处理一些文本行,然后将它们插入数据库。问题是它没有插入 table nothing.

我知道这可能是因为多个工作人员试图修改数据库,但我已经尝试了很多方法来避免这种情况。

例如这个(这是将url插入索引table的方法):

def insert_into_index(self, url):
    self.lock.acquire()
    self.cur.execute('INSERT INTO index VALUES(?)', (url,))
    self.conn.commit()
    self.lock.release()

或者这个(方法的每次新使用都有它自己的游标):

def insert_into_index(self, url):
    cur = self.conn.cursor()
    cur.execute('INSERT INTO index VALUES(?)', (url,))
    self.conn.commit()

我创建池的片段:

 """ CREATE A POOL """

    pool = Pool(50)
    for category in categories[1:2]:
        task = pool.apply_async(index, args=(category.strip('\n'),))
        task.get()

    pool.close()
    pool.join()

    """ POOL END """

Index() 是一种创建 class leaf(text) 实例的方法,它对文本做一些事情,获取 strings 的列表并尝试 insert 将它们存入数据库。

class leaf():
    def __init__(self, url):
        self.url = url
        self.results = self.get_all_hrefs(url)
        self.dbm = database_file.manager()

        for res in self.results:
              self.dbm.insert_into_index(res)

但我在 table 索引中什么都没有。我已经尝试了我所知道的一切但没有成功。你能给我一个建议吗?

编辑:这是在我将 task.get() 附加到循环中时引发的错误。

line 86, in execute
    task.get()
  File "C:\Python27\lib\multiprocessing\pool.py", line 567, in get
    raise self._value
sqlite3.OperationalError: near "index": syntax error

但我认为它并没有说明任何问题,因为语法与另一种按顺序调用并起作用的方法完全相同。

index 是一个 keyword。 您必须引用它,或者使用不同的名称。