use & threadsafety of MySQLdb in Zope if not using DA?
I am working on a generic toolkit for a user registration system that requires a toolkit/API for abstracting relational database access to a MySQL-based user profile database; I do this with a class that handles all the business logic of my application's core toolkit and data-access functionality. The toolkit is written in Python using MySQLdb and will be used by automation utilities, a proxy authorization system, and also within Zope via a python product I am writing. Since I'm doing this in order to have a unified API among all my apps using this database, but without the help of a DA, I'm wondering how I would go about creating a database connection object via my API in a way that works with Zope. My concerns are: 1 - I don't know how I would instantiate the object within my Zope folderish container object... The setup is usually simple in Python, I just create the DB object, which opens the DB connection in its __init__()... I'm wondering how I could create something like this 2 - I'm not sure how to make this thing thread-safe? I realize that I would need to deal with the fact that multiple threads of Zope couldn't access/use the same connection object... I guess what I am trying to figure out, is how I would have non-persistent connection objects instantiated for each thread inside Zope upon Zope startup within my product code. I'm not even sure where to start, or if I'm going about this the wrong way; I would prefer not to have to rewrite my data API classes to work with a DA... thoughts? Sean ========================= Sean Upton Senior Programmer/Analyst SignOnSanDiego.com The San Diego Union-Tribune 619.718.5241 sean.upton@uniontrib.com =========================
On Monday 08 October 2001 11:07 am, sean.upton@uniontrib.com wrote:
I guess what I am trying to figure out, is how I would have non-persistent connection objects instantiated for each thread inside Zope upon Zope startup within my product code. I'm not even sure where to start, or if I'm going about this the wrong way; I would prefer not to have to rewrite my data API classes to work with a DA... thoughts?
this is laced with pitfalls since its very app centric to your application. but you might want to give this tss/tls (thread local/specific storage) i made for something similiar a try. /Members/k_vertigo and try something like myfolder def __init__(self, id, title) self.tssdb = ThreadLocalStorage() def getFooObject(): db = self._getDb() db.getMyObjects(type='foo') def _getDb(): db = self.tssdb.get(None) if not db: db = self._open_connection() self.tssdb.set(db) return db def open_connect() basically the idea was to create in memory objects that were not tied to the persistent machinery but didn't have to deal with the extra overhead of locking by keeping per thread copies using get_ident as an accessor. cheers kapil
participants (2)
-
kapil thangavelu -
sean.upton@uniontrib.com