I'm using scoped_session in a single threaded daemon that has infinite loop 
and sleeps after each iteration.
It's only doing queries (does not write to db).

I guess unit of work for this daemon is an iteration.
>From what I'm gathering from documentation, I should create a Session for 
each unit and close (and remove() in case of scoped_session to unregister) 
when the unit is done.

    Session = scoped_session(...)

    while True:
        try:
            Session().execute...
        finally:
            Session.remove()


But, the program is actually doing:

    while True:
        try:
            Session().execute...
        finally:
            Session().rollback()

with no problem. No increasing memory because Session() always returns same 
object (thread local).
Only difference I can observe is that Session().rollback() throws exception 
when database is unreachable during rollback but Session.remove() swallows 
that exception.

Even in this type of program, is it better to always call Session.remove() 
and get new Session object for each unit of work?
I'm trying to see if there's a down side of using same Session for life 
time of application.


Thanks.
Sam

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to