Martijn Faassen wrote:
Laurence Rowe wrote:
We'll have to stick with scoped sesssions because of threading, but
the engine as local utility pattern should still work.
Session = scoped_session(sessionmaker(bind=LookupEngine('my-engine')...))
engine = EngineUtility(url='sqlite:///')
provideUtility(engine, IConnectable, 'my-engine') # but normally a
local utility registration
from myapplication import Session
session = Session()
Here one still needs to instantiate the session each time you use it.
Couldn't you simply do:
... [what you had]
session = Session()
from myapplication import session
or wouldn't that be possible?
No. It would be similar to doing:
txn = transaction.get()
(if we imagined for a moment that transactions were recyclable objects)
Individual sessions are not thread safe. The point of a scoped session
is that you get a different session depending on which thread you are in.
One (perhaps the only) advantage I can see with looking up the scoped
session as a utility is that it gives the integrator control over
whether to use one or two phase commit, as this is set in the session
configuration. Normally one would prefer one-phase commit as it is
faster, but if an integrator arranged for two applications to be
modified in a single transaction she would want to configure two-phase
How common would it be that the integrator would do this without the
code itself needing to be changed for other reasons then too? A WSGI
How long is a piece of string ;-) Elsewhere in this thread I have an
imaginary departmental address book, one instance of the app per
department. In this example the integrator would not have to change
anything in the Address Book app. But then they want to create another
app that allows them to search and replace across all address books. For
this to work correctly they should reconfigure the address book app to
use multiple two phase commit.
I imagine we could arrange something where we allow both. Provide the
engine as local utility scenario, but let people register sessions as
local utilities should they want to.
Maybe this should be configured somewhere else than a local utility. I
wander how Pylons does it.
Zope-Dev maillist - Zope-Dev@zope.org
** No cross posts or HTML encoding! **
(Related lists -