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语句的查询。

  • 相关阅读:
    Android Developer API Guides
    Ubuntu 12.04 下安装 VirtualBox
    C++的异常处理
    JZOJ 4246. 【五校联考6day2】san
    JZOJ 4245. 【五校联考6day2】er
    JZOJ 4244. 【五校联考6day2】yi
    JZOJ 4228. 【五校联考3day2】C
    JZOJ 4227. 【五校联考3day2】B
    JZOJ 4226. 【五校联考3day2】A
    JZOJ 4235. 序列
  • 原文地址:https://www.cnblogs.com/xiami303/p/3309391.html
Copyright © 2011-2022 走看看