Dear all, I'm starting a web project based on Python, and I've decided to rely on web.py and SQLAlchemy. My DB is for the moment a SQLite database, and I'm trying to figure out how the framework deals with sessions / transactions. Your help would be greatly appreciated !
Here's how I declare my global Session : engine = create_engine('sqlite:///.....', echo = True, listeners=[MyListener()]) Session = scoped_session(sessionmaker(bind=engine)) Q1) The documentation recommends to use that kind of scoped_session for a web project : why, actually ? What if I use "regular" sessions ? What would happen in that case if different users of my site would get their own sessions ? I've made a simple test : I declare 2 actions, 'add' and 'commit'. 'add' deliberately doesn't commit the Session because I want to understand the behavior of the framework. class Add: def GET(self, name=None): print Session.connection() print engine.pool.__dict__ for conn in engine.pool._all_conns: print "[CONN] %s" %conn if prenom is not None : user = User(name) Session.add(user) # No commit here class Commit: def GET(self): Session.commit() I ran several tests : I triggered the 'Add' action from different browsers, adding 'Jack' then 'John'.... Sometimes 'Jack' appears in Session.new, sometimes not. Sometimes Session.new is empty, sometimes not. It seems to depend on the underlying connection of the session. Q2) Why's that ? Shouldn't the session be somehow "global" ? Why doesn't it encapsulate all my users ? Q3) Moreover, what happens to the connections I open when I add a user without committing ? Why are they recycled by the framework on the next call ? My listeners indicates they're never checked-in (except on commit time) Q4) When I run the "commit" action, it seems to randomly pick a connection and flush the objects. Why's that ? Besides , I'm trying to restrict pool_size to 1 in the engine. Q5) It does not seem to change anything : more and more connections are open when I run "add" multiple times. How could I actually restrict the pool size ? Q6) What is the best strategy when using scoped_session in a web project ? Forgetting a commit seems to have very dangerous consequences (delayed flush). Thanks very much for your help ! Franck -- 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.