> 
> On Jan 7, 2013, at 7:20 PM, Diego Woitasen wrote:
> 
>> 
>> I'm back to this :)
>> 
>> My problem was that I'm not closing the session properly.  
>> 
>> My new question is... is there a way to autoclose the session? My example, 
>> at the end of the scope?
>> 
>> What's the recommend way to do this?
>> 
>> I've read the FAQ, but it's not very clear for me.
> 
> you need to structure your application such that database operations occur 
> within a consistent framework.
> 
> This is the simplest when using web frameworks, as all frameworks include 
> some kind of " request end" hook - that's where the close of the Session 
> would go.
> 
> Looking at your example again, I see you have a "print delivery.name, 
> delivery.status" after you've done your commit().  That would be a likely 
> source for the new connection here, as accessing those attributes means the 
> Session needs to go back to the database post-commit to get their most recent 
> value.

Hi Michael / Diego - I also have a couple of questions in this area, so I 
though I would jump on this thread.

So, if you close down a Session with Session.close() is the Engine associated 
with that session (e.g. Session(bind=e) ) then freed up as far as the pool etc 
is concerned or is there something else I need to do to the Engine?

If I have a result proxy and it simply gets garbage collected - is that 'freed' 
as far as SQLA is concerned or do I need to specifically do something to clean 
it up (other than exhausting it)?

The issue I'm having is that 'sometimes' my app gets handed a dead connection 
to the MySQL server which tends to make things unhappy.  It is a home grown 
framework, however it is well structured and has clear Entry and Exit points 
for closing down any Session objects etc.  *Somewhere* I am leaving something 
dangling and it's getting closed down by MySQL with a connection timeout.

Finally, I'm using multi Session objects (potentially) within a threaded 
environment.  i.e. Each thread may or may not have one or more Sessions created 
using sessionmaker(). (A second Session would typically be because of some 
nested requirement)  This appears to work fine, or am I missing something?  
Each new Session is bound to the engine directly - and it *could* be a 
different Engine to other Sessions.

Thanks for all your help.

Cheers
Warwick

-- 
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?hl=en.

Reply via email to