GlobalSession = scoped_session(session_maker(bind=engine, transactional=False))

def connect(thread_index):
    cherrypy.thread_data.scoped_session_class = GlobalSession

def open_dbsession():
    cherrypy.request.scoped_session_class = (cherrypy.thread_data.
        scoped_session_class)

def close_dbsession():
    cherrypy.request.scoped_session_class.remove()
Best practice for integrating CherryPy web-framework, SQLAlchemy sessions and lighttpd to serve a high-load webservice