[mod_python] avoiding database connection leak on module (re)import

Mark Harrison mh at pixar.com
Mon Dec 4 03:05:50 EST 2006


Whenever the source file is modified, mod_python re-imports the
file.  A naive program will have a connection leak if it just
has a line like this:

myconnection = mydbpackage.connect(...)


So, I'm closing and reopening the connection on each re-import:

try:
     myconnection.close()
except NameError:
     pass
myconnection = mydbpackage.connect(...)

Is there a better, more  mod_pythonic way to handle this type of
situation?

Many TIA!
Mark

-- 
Mark Harrison
Pixar Animation Studios


More information about the Mod_python mailing list