J
JZ
I have problems with many concurrent request for Webware. I get the
error:
SQLError: (2014, "Commands out of sync; You can't run this command
now")
MyDB.py
=======
from MyDBPool import datapool
class MyDB(Config):
def __init__(self):
self.conn = None
self.cursor = None
self.rowcount = 0
def dbConnect(self):
self.conn = datapool.getConnection()
self.cursor = self.conn.cursor()
def dbDisconnect(self):
if self.cursor:
self.cursor.close()
if self.conn:
self.conn.close()
def execute(self, sql):
self.dbConnect()
self.rowcount = self.cursor.execute(sql)
self.dbDisconnect()
return self.rowcount
#...
MyDBPool.py:
==========
# inspired from
#http://sourceforge.net/mailarchive/forum.php?thread_id=2693193&forum_id=3505
from Config import Config
import MySQLdb, MySQLdb.cursors
from MiscUtils.DBPool import DBPool
datapool = DBPool(MySQLdb, 20, host=Config.dbHost, user=Config.dbUser,
passwd=Config.dbPasswd, db=Config.dbName , compress=0,
cursorclass=MySQLdb.cursors.DictCursor)
I do not know how to fix it. I tried change above method to:
def execute(self, sql):
_cache_lock = thread.allocate_lock()
_cache_lock.acquire()
self.dbConnect()
self.rowcount = self.cursor.execute(sql)
self.dbDisconnect()
_cache_lock.release()
return self.rowcount
But it could not help.
error:
SQLError: (2014, "Commands out of sync; You can't run this command
now")
MyDB.py
=======
from MyDBPool import datapool
class MyDB(Config):
def __init__(self):
self.conn = None
self.cursor = None
self.rowcount = 0
def dbConnect(self):
self.conn = datapool.getConnection()
self.cursor = self.conn.cursor()
def dbDisconnect(self):
if self.cursor:
self.cursor.close()
if self.conn:
self.conn.close()
def execute(self, sql):
self.dbConnect()
self.rowcount = self.cursor.execute(sql)
self.dbDisconnect()
return self.rowcount
#...
MyDBPool.py:
==========
# inspired from
#http://sourceforge.net/mailarchive/forum.php?thread_id=2693193&forum_id=3505
from Config import Config
import MySQLdb, MySQLdb.cursors
from MiscUtils.DBPool import DBPool
datapool = DBPool(MySQLdb, 20, host=Config.dbHost, user=Config.dbUser,
passwd=Config.dbPasswd, db=Config.dbName , compress=0,
cursorclass=MySQLdb.cursors.DictCursor)
I do not know how to fix it. I tried change above method to:
def execute(self, sql):
_cache_lock = thread.allocate_lock()
_cache_lock.acquire()
self.dbConnect()
self.rowcount = self.cursor.execute(sql)
self.dbDisconnect()
_cache_lock.release()
return self.rowcount
But it could not help.