do not unnecessarily close the database connection (fixes #20)
This commit is contained in:
parent
431519f9e3
commit
72a02a6e95
2 changed files with 2 additions and 5 deletions
|
@ -11,10 +11,8 @@ from pylons.i18n import _, ungettext, N_, add_fallback, set_lang
|
||||||
from pylons.templating import render
|
from pylons.templating import render
|
||||||
|
|
||||||
import pyalchemybiz.lib.helpers as h
|
import pyalchemybiz.lib.helpers as h
|
||||||
import pyalchemybiz.model as model
|
|
||||||
|
|
||||||
from pyalchemybiz.model import meta
|
from pyalchemybiz.model import meta
|
||||||
from sqlalchemy.orm import sessionmaker
|
|
||||||
|
|
||||||
|
|
||||||
class BaseController(WSGIController):
|
class BaseController(WSGIController):
|
||||||
|
@ -31,13 +29,11 @@ class BaseController(WSGIController):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
# connect to database
|
# connect to database
|
||||||
conn = meta.engine.connect()
|
|
||||||
meta.Session.configure(bind=conn)
|
|
||||||
try:
|
try:
|
||||||
return WSGIController.__call__(self, environ, start_response)
|
return WSGIController.__call__(self, environ, start_response)
|
||||||
finally:
|
finally:
|
||||||
meta.Session.remove()
|
meta.Session.remove()
|
||||||
conn.close()
|
|
||||||
|
|
||||||
# Include the '_' function in the public names
|
# Include the '_' function in the public names
|
||||||
__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \
|
__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \
|
||||||
|
|
|
@ -16,6 +16,7 @@ def init_model(engine):
|
||||||
|
|
||||||
meta.engine = engine
|
meta.engine = engine
|
||||||
meta.Session = orm.scoped_session(sm)
|
meta.Session = orm.scoped_session(sm)
|
||||||
|
|
||||||
person.t_person = sa.Table(
|
person.t_person = sa.Table(
|
||||||
'person', meta.metadata, autoload=True, autoload_with=engine)
|
'person', meta.metadata, autoload=True, autoload_with=engine)
|
||||||
customer.t_customer = sa.Table(
|
customer.t_customer = sa.Table(
|
||||||
|
|
Loading…
Reference in a new issue