For clarity I made a table below in my notes out of reading the 
documentation and generalize the points:

Engine: no worries, Engine object is always thread safe.
Session: Session objects are tricky, they can be quite dangerous to use in 
a multi-threading context if one is not careful. Forget about 
scoped_session(), it's only for pros. Just remember to create a Session 
object when a thread starts and close it before a thread ends. That way we 
can ensure that the said Session object is local to one particular thread.
Connection: This is the most dangerous part. You can create a Engine object 
and a Session object outside of the current thread, as long as you bind 
those two together from the current thread to get a Connection that is 
local to current thread, then throughout this thread's lifespan the entire 
system will be thread safe. Before that particular thread ends, just close 
the session object.


Can some advanced user help review it if there is any flaws in those 
points? I'm thinking to write a blog to explain these stuff to newbies, I 
found current documentation is fine but a little too technical for beginner 
users. Thanks.

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to