On Jun 10, 2013, at 11:46 AM, Ladislav Lenart <lenart...@volny.cz> wrote:
> > I have no idea what is wrong. Please help me diagnose this! Note that OS > monitor > shows several cherrypy threads, each gets its share, so the cherrypy setup > seems > to be OK. > class _SessionContext(object): > def __init__(self): > self._level = 0 > > def __enter__(self): > if self._level == 0: > self._session = _Session() > self._level += 1 > return self._session > > def __exit__(self, type_, value, traceback): > self._level -= 1 > if self._level == 0: > self._session.close() > self._session = None > > _thread_local = local() > > def get_session(): > ctx = getattr(_thread_local, 'session_context', None) > if ctx: > return ctx > ctx = _SessionContext() > _thread_local.session_context = ctx > return ctx what's all this thread local stuff for? The problem is likely there, a scoped_session() already uses a threading.local. A very simple usage pattern should work fine. Just put a "session.remove()" type of thing to occur at the end of each request. guidelines are here: http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#using-thread-local-scope-with-web-applications -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.