[mod_python] MySQL connections not closing properly

Graham Dumpleton graham.dumpleton at gmail.com
Fri May 25 19:08:48 EDT 2007


There is no guarantee that objects will be destroyed when the process
exits, so you cant rely on __del__ methods being triggered. In fact,
mod_python as it is doesn't currently even shutdown Python
interpreters on normal process exit as it was causing hangs and other
errors. I actually know now why this was the case and how to fix it
but lot of work to fix it all up.

The preferred way at the moment is to register cleanup functions for
mod_python to call on process shutdown. This can be done using
apache.register_cleanup(). See documentation for register_cleanup()
in:

  http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html

Graham

On 26/05/07, Andres Morey <amorey at octopart.com> wrote:
> Hi,
>
> I am using mod_python 3.3.1 with Python 2.5, Apache 2.2.4, MySQL
> 5.0.27 and MySQLdb 1.2.2. When I stop the server I get "Aborted
> connection" warnings in MySQL even though I am closing the database
> connections properly when an object goes out of scope (by using the
> __del__ method). These warnings only happen when a python instance
> with an open database connection is killed abruptly, so I think it
> has something to do with the way that mod_python shuts down the
> python interpreter.
>
> How does mod_python shut down the python interpreter? Is there a good
> way to handle when mod_python shuts down the python interpreter?
>
> Thanks,
> Andres
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


More information about the Mod_python mailing list