[This message has also been posted.]
See followup comment below...

On Sat, 15 May 2010 07:44:04 -0700 (PDT), Michael Bayer 
<mike...@zzzcomputing.com> wrote:
>
>
> On May 15, 2:52 am, Faheem Mitha <fah...@email.unc.edu> wrote:
>> Hi,
>>
>> I was trying to figure out a way to close all connections to a db.
>>
>> Apparently
>>
>> db = create_engine(dbstring)
>> conn = db.connect()
>> [...]
>> conn.close()
>>
>> doesn't actually close the connection initiated by conn. I have to call
>>
>> db.dispose()
>>
>> which seems to do so, though I cannot find any clear documentation that
>> says so. It would be nice if this was mentioned in the section that
>> describes connections.
>
> its mentioned in pool.dispose() and engine.dispose() is likely missing
> a docstring (also the 0.5 docs are not nearly as up to date as those
> of 0.6).  the method is not guaranteed to close all open connections,
> only those which are not currently checked out.

Belated update - I just looked at this message again, and realised I
don't have a clear idea of what 'checked out' means in this
context. The term is used in
http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/pooling.html
several times for example, but I don't see an actual definition there.

                                                      Regards, Faheem.

>> In any case, I'm writing to ask what recommended usage for connecting to a
>> db is. Let's say I am writing a script which has various functions
>> connecting to the same db. Should I pass around a db string corresponding
>> to the engine, or should I pass around an engine itself, or should I pass
>> around a connection object? I suppose the third might cause problems,
>> since presumably only one user can use a connection at a time.
>
> passing a connection between various methods and functions  implies a
> single thread of execution so there's no concurrency concern there, if
> that's what you mean by "one user".  The issue comes down to how you'd
> like your application to deal with transactions, whether you'd like a
> group of operations to proceed on the same Connection (can be made to
> be on all one transaction more easily) or not.   A lot of related
> discussion is at http://www.sqlalchemy.org/docs/dbengine.html,
> including the discussion about transactions, threadlocal strategies,
> etc.   But none of that makes a choice for you.
>
>
>> If so, with option 1, when passing dbstring to a function, should I close
>> the connection and dispose of the created engine,
>
> option 1 is not an option here and is vastly inefficient.  your
> application should have one engine per database backend.
>

-- 
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.

Reply via email to