On Oct 31, 2011, at 12:56 PM, Benjamin Sims wrote:

> I suspect that my understanding of both threading and Sessions is going to be 
> found pretty wanting here; I've basically just lifted things from 
> Pyramid/SQLAlchemy examples.
> 
> My understanding is that the framework handles threading, and that based on 
> examples and 
> http://www.sqlalchemy.org/docs/orm/session.html#contextual-thread-local-sessions
>  this is the correct way to create a session available throughout the request:
> 
> DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
> 
> (this is in my models file)
> 
> I then use this either by doing:
> 
> DBSession.query()
> 
> or
> 
> from models import DBSession
> session = DBSession()
> session.query()
> 
> So, I'm not doing anything explicit in turns of ending the session - I guess 
> I should be, but I had understood that this would happen on issue of next 
> query/completion of request.

that's a question for the Pyramid folks.     There should also be a single path 
for handling of exceptions - any unexpected exception would propagate to the 
same point, there's a Session.rollback() right there, and it gets reported.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@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.

Reply via email to