Chris Withers wrote: > Michael Bayer wrote: >>> If finishing with a .remove() is a big deal in your environment, which >>> it seems like it is, you could do a .remove() at the start of the >>> request instead. >> >> You really don't need the "remove()" if you have definitely called >> commit() or rollback() last, and you have expire_on_commit=True. In >> most >> cases the session will be empty on the next request. > > When could it not be empty
if GC has not removed objects from it yet, or you otherwise are still referencing those objects after you've finished your request. > and would that matter? if your application keeps a handle on objects after the request is complete, and then passed them somewhere else, like a background thread or something, then the subsequent request is going to be potentially touching those objects at the same time. This would all be pretty poor practice as individual threads should always have their own sessions. Or maybe you loaded those objects into a globally-scoped in-memory cache of some kind - you probably don't want the next request touching them directly as once they're in a global cache of some kind, other threads would be calling upon them to copy their state locally. On the other hand, you might load the objects into a session-local cache of some kind that you've created. Now, when the next request comes in and calls upon those same rows, the ORM doesn't need to re-instantiate the objects, they are already present in the cache. This is a use case where you'd want to keep the same session from one request to the next. Its not one I use, but there is another....ORM like thing, somewhere on the web....where I'm pretty sure they use a scheme like this. > > Are there any other implications of calling neither .remove() nor > .close()? I have a (hopefully) paranoid worry about connections not > being returned to the pool and/or "going away" in typical MySQL style... the bulletpoints at http://www.sqlalchemy.org/docs/session.html#lifespan-of-a-contextual-session are the best I can do here, I'm really just repeating myself over and over in these threads.... > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk > > -- > 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. > > -- 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.