[url]http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg07933.html[/url]
an example of a typical Session lifecycle as placed in a web
application is here:
http://www.sqlalchemy.org/docs/04/session.html#unitofwork_contextual_lifespan
theres no "reconnecting" going on explicitly on your end. the Session
itself typically lasts for the span of a single web request, after
which it is either discarded, or closed which releases its resources
until the next web request where it can be used again.
When using scoped_session(), you automatically get thread local
behavior out of it so simply calling Session.remove() or
Session.close() at the end of a request should be sufficient.
So in your code youd want to only call get_database exactly once for
the entire application, and you'd want to use scoped_session() to
account for multiple threads. :arrow:
an example of a typical Session lifecycle as placed in a web
application is here:
http://www.sqlalchemy.org/docs/04/session.html#unitofwork_contextual_lifespan
theres no "reconnecting" going on explicitly on your end. the Session
itself typically lasts for the span of a single web request, after
which it is either discarded, or closed which releases its resources
until the next web request where it can be used again.
When using scoped_session(), you automatically get thread local
behavior out of it so simply calling Session.remove() or
Session.close() at the end of a request should be sufficient.
So in your code youd want to only call get_database exactly once for
the entire application, and you'd want to use scoped_session() to
account for multiple threads. :arrow: