【发布时间】:2012-10-14 07:10:15
【问题描述】:
编辑: 这个问题令人难以置信。我现在已经设法用 time.sleep(0.01) 替换了烦人的打印功能,但究竟为什么我应该从更慢的执行时间中受益,这超出了我的理解。
我在 Python 3.23 的 MySQL 1.0.7 连接器中迭代光标时遇到问题。
除非 print() 每次迭代的结果(这既愚蠢又耗时)我会引发以下错误:
引发错误。InterfaceError(errno=2013) mysql.connector.errors.InterfaceError: 2013: 失去与 MySQL 的连接 查询期间的服务器
有什么想法吗?
到目前为止,代码很简单:
self.config = {'user': user,'password': password,'host': host,'database':
database,'raise_on_warnings': True}
self.data = []
self.clickcnx = mysql.connector.connect(**self.config)
self.clickcursor = self.clickcnx.cursor()
query = "SELECT table1, table2, table3 FROM `db`-tables;"
self.clickcursor.execute(query)
for item in self.clickcursor:
print(item) #this is the strange line that I need!
self.data.append(item)
self.clickcnx.close()
【问题讨论】:
-
请发布触发此问题的代码。
-
就我而言,“解决方案”是 time.sleep(0.000001) (这是我能找到的不会触发错误的最小睡眠时间)。真的很奇怪,但感谢发布。你找到合适的解决方案了吗?
标签: python mysql mysql-connector-python