SQLError: (2014, "Commands out of sync; You can't run this command now")

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. :(
 
D

Dennis Lee Bieber

JZ fed this fish to the penguins on Tuesday 07 October 2003 07:17 am:

def execute(self, sql):
self.dbConnect()
self.rowcount = self.cursor.execute(sql)
self.dbDisconnect()
return self.rowcount

Just out of curiosity, do you ever do anything with the data from the
query? All you return here is the affected rows (I believe) and you
close the cursor/connection which likely trashes any results.

You don't show the application generating the error(s) -- what type of
operation was requested?

--
 
J

JZ

Just out of curiosity, do you ever do anything with the data from the
query?

No. I have just typed part of my code.
All you return here is the affected rows (I believe) and you
close the cursor/connection which likely trashes any results.

No. For my convenience, I created methods based on PEAR syntax. E.g.
getAll(), getMany(), getOne() which return desired values without
explicit using cursors or fetchone() methods of API 2.0
You don't show the application generating the error(s) -- what type of
operation was requested?

I got advise from webware maillist, that it is MySQLdb problem. I
appears during using one db connection and more than one cursors
working on two or more servlets parallelly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top