【发布时间】:2014-12-25 01:58:36
【问题描述】:
我写了一个这样的python程序,它应该在多线程模式下运行:
def Func(host,cursor,db):
cursor.execute('''SELECT If_index, Username, Version, Community, Ip_traff FROM HOST WHERE
Hostname = ?''',(host,))
#do something
#--- Main ---
db = sqlite3.connect(os.getcwd()+'\HOST', check_same_thread = False) #opendatabase
cursor = db.cursor() #generate a cursor
for ii in range(len(host)): #host is a list of ipaddress
#for each host i want generate a thread
thr = threading.Thread(target = Func, args=(host[ii],cursor,db)
thr.start()
我收到 sqlite3.ProgrammingError: Recursive use of cursors not allowed。在这种情况下,如何管理 sqlite3 的递归游标? 多谢 保罗
【问题讨论】:
-
你为什么不给每个线程自己的光标?
标签: python multithreading sqlite database-cursor