FAQ
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&93193&forum_id505
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. :(

--
JZ ICQ:6712522

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedOct 7, '03 at 2:17p
activeOct 8, '03 at 9:57a
posts2
users1
websitepython.org

1 user in discussion

JZ: 2 posts

People

Translate

site design / logo © 2022 Grokbase