Skip to content

Instantly share code, notes, and snippets.

@agronholm
Created March 17, 2014 16:19
Show Gist options
  • Save agronholm/9602522 to your computer and use it in GitHub Desktop.
Save agronholm/9602522 to your computer and use it in GitHub Desktop.
class BaseRequestHandler(RequestHandler):
__dbsession = None
@property
def dbsession(self):
if not self.__dbsession:
self.__dbsession = Session(self.application.settings['engine'], expire_on_commit=False)
return self.__dbsession
def on_finish(self):
if self.__dbsession:
try:
if self._status_code < 300:
self.__dbsession.commit()
finally:
self.__dbsession.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment