2
我很絕望,因爲我試圖盡我所能,使其工作,但沒有成功。我已經創建了一個池,其正在處理一些文本行,然後將它們插入到數據庫。問題是它沒有插入到表中。不能插入到數據庫SQLITE3
我知道這可能是因爲多工人試圖修改數據庫,但我已經嘗試過很多事情,以避免這種情況。
例如,這(這是將URL到索引表的方法):
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()是一種創建類的實例的方法,該做一些事情與文本,得到的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)
但我沒有什麼表索引。我已經嘗試了我所知道的沒有成功的一切。你能給我一個建議嗎?
編輯:這是當我追加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
但我的東西,它並沒有告訴任何事情,因爲語法是完全一樣被稱爲順序和作品的另一種方法。
'任務= pool.apply_async(指數,ARGS =(category.strip( '\ n')))'有應該是後' '''的東西嗎? – Busturdust