How to make sure all connections are closed?

36 views
Skip to first unread message

Oltmans

unread,
Jul 18, 2012, 3:07:57 AM7/18/12
to sqlal...@googlegroups.com
Hi all, 

I've a Django app, structure of which looks something like http://codepad.org/Tha7ySNL . This app is serving few hundred customers and lately network admin said he's been seeing lot of open connections. What can I do to make sure there are no open connections? 

Is there anything that can guarantee there are no more open connections? 

All help will be really appreciated. 

Michael Bayer

unread,
Jul 18, 2012, 9:29:13 AM7/18/12
to sqlal...@googlegroups.com
some of that code looks a little weird, you've got "runs a statement and returns one result", but it appears to return the whole result set from execute() - but then you call close() on it, which means you won't be able to get any rows from it.  so I'm guessing that's not the actual code.
  
the specifics of how you deal with these result sets, which you're getting via a method SQLA calls "connectionless, implicit execution", would determine if connections are staying open too long or not.  If you get a result from execute(), then fetch a few rows from it, then forget about it, the connection for that result is still checked out from the pool and reserved for that result for any amount of time, until the result object is garbage collected.  

So you want to make sure the result objects get closed out in all cases, which usually means calling fetchall() on them or otherwise getting all results unconditionally.   

then you might want to reduce that number of connections down, 20 is quite high, and if you dont want connections to be open at all when the pool is dormant, use NullPool.   More details at http://docs.sqlalchemy.org/en/rel_0_7/core/pooling.html .



--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/PflV-kxCJCcJ.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

Reply all
Reply to author
Forward
0 new messages