您的位置:首页 > 数据库 > MySQL

_mysql_exceptions.ProgrammingError:(2014, "commands out of sync; you can't run this command now")

2013-09-09 10:47 239 查看
今天,测试dashboard上的一些graph, 发现,当多个graph同时向后台请求数据(异步)的时候, 出现了上述错误。而且,三个bug交替出现,另外两个bug分别是:python stop response 和mysql close closed connection。

查到最后,发现,因为ajax是异步请求的,而后台处理的时候,建立了一个connection以后,执行多条sql语句的时候,就出现了上述错误。

出错地方:

  


错误代码:  

def ExceptionHandling_mysql(self,sql):
try:
cur = self.conn.cursor(libdb.cursors.DictCursor)
rowcount = cur.execute(sql)
self.conn.commit()
result = cur.fetchall()
while cur.nextset(): pass
#if cur:
#cur.close()
except Exception, e:
print 'This is mysql: %s' % (sql)
print e
result = []

#self.conn = libdb.connect(host=configeApp.getDBHost(), port=configeApp.getDBPort(), user=configeApp.getUserName(),
#passwd=configeApp.getPwd(), db=configeApp.getDBase(), use_unicode=True, charset='utf8')
if cur:
cur.close()
if self.conn:
self.conn.close()
return result


最终问题解决,改成一个connection,进行一个sql语句的查询。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐