closing database connections

Brian Kelley bkelley at wi.mit.edu
Fri Jan 23 16:09:58 EST 2004


andy wrote:

> I seem to remember reading somewhere that as client connections are a finite 
> (and often scarce) resource, it's not the client but the server that will 
> suffer when you do this.

I think there might be two issues here.  One is using the reference 
counting scheme to close files and databases, the other is to keep 
connections open, which andy seems to be referring too.

This discussion has occured a lot in the python community.  I'll give a 
case in point.  The python interface to metakit has no close method.  It 
can only be closed through reference counting and by going out of scope.

The problem with this, is that if some piece of code has a reference to 
the metakit database, it will *never* be closed and this causes hard to 
find bugs with metakit.  In C-python reference counting closes files and 
database connections "soon" after they go out of scope.  This may or may 
not be true in java python.  I haven't tested this.

The upside is that if you explicitly close the database, it will be 
closed when you expect and you don't have to worry about other objects 
having a reference to your cursor or connection or what not.

That being said, just relying on the reference count and letting python 
clean up has worked very well for me with metakit.

> hth,
> -andyj
> 
> 




More information about the Python-list mailing list