[SQLObject] Re: sharing, freeing connections, transactions
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Randall S. <ra...@tn...> - 2005-11-14 03:01:20
|
Ian Bicking wrote: > Randall Smith wrote: > >> Randall Smith wrote: >> >>> Some questions about connections. >>> >>> How does one: >>> >>> 1. Share a SQLObject connection outside of SQLObject? Using a >>> transaction? >> >> >> Like this? >> shared = con.getConnection() >> .... >> con.releaseConnection(shared) This doesn't seem to workout with transactions. I guess the getConnection method is getting a new connection even if con is a transaction. Instead, I'm doing this now. sqlocon = connectionForURI('postgresql://dba:...') trans = sqlocon.transaction() rawcon = trans._connection # Do some stuff with SQLObject and non-SQLObject code. # Commiting stuff here and there. del rawcon Calling rawcon.close() actually closes the connection. So instead I'm using del I'm a bit concerned about this. Is there a chance the connection could close? Do you know a better approach? Randall > > > I think this would be fine. You don't actually have to release the > connection, either; I think it will just be safely garbage collected if > you don't. > >>> 3. Insure unused connections are closed (no pooling). >> >> >> It appears that con._pool = None will do this, but is this the best way? > > > For now, yes. I do use this in some of my own projects, on machines > that are connection starved (I actually haven't had the problem of 20 > connections -- and that may be improved for you in svn trunk -- but in > this case even 2 or 3 connections was taking up too many). > |