0
我使用Python 2.7和SQLite3数据库。我想在数据库上运行需要一些时间的更新查询。另一方面,我不希望用户必须等待。 因此,我想开始一个新的线程来做数据库更新。多线程和Python SQL3
Python引发错误。有没有一种有效的方式来告诉数据库在它自己的线程中执行更新,而无需等待线程完成?
line 39, in execute ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 3648 and this is thread id 6444
至于示例去我试图写一个Anki插件。产生这个错误的附加组件的代码是:
from anki.sched import Scheduler
import threading
def burying(self, card):
buryingThread = threading.Thread(target = self._burySiblings, args = (card,))
buryingThread.start()
def newGetCard(self):
"Pop the next card from the queue. None if finished."
self._checkDay()
if not self._haveQueues:
self.reset()
card = self._getCard()
if card:
burying(self, card)
self.reps += 1
card.startTimer()
return card
__oldFunc = Scheduler.getCard
Scheduler.getCard = newGetCard
这将是有帮助的独立的例子。 –