On Oct 24, 2006, at 10:46 AM, Gary D wrote: > OK, calling dispose() on the engine seems to work just fine. I've > noticed that there are always two connections though, even in this > simple scenario. Is that normal? >
the pool does not create any connections until called. if two connections are getting created, it would imply two operations are going on , where the second operation starts before the first has closed its Connection proxy. > During my processing I obviosuly select stuff, modify it and save it > back using a session. If I turn on INFO level logging I can see > that SA > is also putting one of these connections into the pool and immediately > getting it out again between the SELECTs and the UPDATEs or INSERTs. > This kind of implicit pool swapping seems a bit inefficient. Works > just > fine though so I can't really complain :) its not so inefficient since the connections are pooled, and are simply being shuttled back and forth into a Queue.Queue object. you have several options for optimizing this behavior. the most basic is to use a Connection yourself and bind it to your session; all select and flush operations will use that connection. when your operations are complete, call close() on the connection, and the underlying connection is returned. another is to look into the "threadlocal" strategy which accomplishes the same thing, except it binds the connection to a threadlocal variable where it gets re-used by all (contextual) operations within the current thread. both techniques are described in detail in the docs. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy -~----------~----~----~----~------~----~------~--~---
