zoukankan      html  css  js  c++  java
  • _mysql_exceptions.ProgrammingError:(2014, "commands out of sync; you can't run this command now")

    今天,测试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语句的查询。

  • 相关阅读:
    log4c demo
    c连接redis
    1108. IP 地址无效化
    1295. 统计位数为偶数的数字
    LCP 1. 猜数字
    1281. 整数的各位积和之差
    1313. 解压缩编码列表
    仿射变换及其变换矩阵的理解
    RNN 与 LSTM 的原理详解
    网络深度对深度学习模型性能有什么影响?
  • 原文地址:https://www.cnblogs.com/xiami303/p/3309391.html
Copyright © 2011-2022 走看看