> Concurrency issues can be difficult without a full context. But I
> think this will be a problem.
Sorry for not providing enough information. Here are the relevant
excerpts from my code:
configuration.py:
-------------------------------------------------------------------------
from MiscUtils.DBPool import DBPool
import pgdb
dbuser = "devel"
datapool = DBPool(pgdb, 15, dsn="localhost:edit", user=dbuser)
testpool = DBPool(pgdb, 5, dsn="localhost:edittest", user=dbuser)
Foundation.py:
-------------------------------------------------------------------------
from configuration import datapool
from configuration import testpool
class Foundation:
'''Base class containing convience methods'''
# This class variable is inherited and shared across instances of
# Foundation
db = False
def __init__(self, datasource="datapool"):
self._datasource = datasource
# Allow multiple datasources for debugging purposes
if datasource == "datapool":
self._db = datapool
else:
self._db = testpool
def getDB(self):
'''Pulls a connection out of the database pool'''
if not Foundation.db:
Foundation.db = self._db.getConnection()
return Foundation.db
def commit(self):
'''Commits a transaction'''
Foundation.db.commit()
Foundation.db.close()
Foundation.db = False
SomeChild.py:
-------------------------------------------------------------------------
class SomeChild(Foundation):
def setInfo(self, val):
db = self.getDB()
sql = "INSERT INTO sometable (val) VALUES (%(val)s)"
cursor = db.cursor()
cursor.execute(sql, {'val' : val})
return cursor.rowcount
This setup allows me to share the DB conneciton among multiple objects,
all of which inherit from Foundation:
child1 = SomeChild()
child2 = SomeChild()
child1.setInfo(3)
# Nothing has been commited yet
child2.setInfo(4)
# Nothing has been commited yet
child1.commit()
# Both inserts are committed
If this is going to cause problems with thread safety, is there a way I
could get around it using locking or something? If not, how should I
approach sharing a database conneciton among multiple objects? Sorry the
example is so long, and BTW, I haven't tested the above SomeChild class
because I just made it up on the fly. Thanks in advance for any help
provided!
Sincerely,
Travis Whitton <[EMAIL PROTECTED]>
-------------------------------------------------------
This SF.NET email is sponsored by: eBay
Great deals on office technology -- on eBay now! Click here:
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss