thx michael, we are using pyramid_tm which use zope.sqlalchemy.
we decare scoped_session like this
my_session = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
but ... we are dealing with lots of databases. For that we store the scoped_session inside a static dict
when pyramid start, we list all databases names and init all scoped session with get_session method.
We close the session the first time she's created where pyramid is launched.
sample of our code
MyDbManager(object)
_dictToScopedSession = {}
@classmethod
def get_session(cls, db_name):
if db_name and db_name not in _dictToScopedSession :
try :
local_sess = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
configure_dbsession(local_sess, cls._settings, 'delivery.dbcnx.temps.', metadata=None, codmar=oldcodmar.upper())
local_sess.close()
except DatabaseError :
log.error('sorry no database named %s'%db_name)
else :
cls._dictToScopedSession[db_name]=local_sess
return cls._dictToScopedSession.get(db_name)