On Dec 22, 2009, at 3:03 PM, Igor Katson wrote: > Hi, > > when a request comes into my webapp, pylons makes a shiny new > threadlocal Session for this request (thread), and it's perfectly fine. > However, after returning the result to the client, I want to be able to > continue processing in a separate thread, but not use another session > (another db connection) and continue using the existing one. > > Is there a way to accomplish this? > > Thanks in advance, > Igor Katson.
the actual session object is obtained from the "scoped" session by calling it: mysession = Session(). You want to modify the BaseController in your Pylons project to not close out the contextual session at the end - or alternatively, you can "detach" the existing session: mysession = Session() Session.registry.clear() the "scoped" session will no longer have a handle to "mysession", and you can send along "mysession" to your worker thread for further operations. If it were me, the above approach is error prone and complicated. I simply transfer the state I need from the request-level Session to that of my deferred worker thread using newobj = Session.merge(obj, dont_load=True). The merge will copy the state of the given object into the new session, and dont_load=True ensures that no SQL is emitted when this occurs - you have to be sure that a concurrent transaction somewhere isn't modifing the data you're passing, or you'd be operating on stale information in that case. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.