On 11/6/06, Neil Schemenauer <nas arctrix.com> wrote:
> Arturo FM <artufm yahoo.es> wrote:
> > I'm writting a web application using Quixote 2. I
need to reuse
> > database connections. I have seen the Wiki but
it's about Quixote
> > 1. I'm using mod_scgi (Apache) and the
'scgi_server.py' script.
> > I wrote a new class that inherit of Publisher. In
its constructor
> > I connect to dabase. But, where I can to
disconnect it?
>
> scgi_server.py is designed for long running application
servering
> daemons and so there is no cleanup mechanism provided.
Normally a
> DB connection is created when the application server
starts (e.g.
> when the publisher object gets created) and is kept
open.
>
> If you really need cleanup then I guess you could use
the "atexit"
> module. Why do you think you need a cleanup method
though?
I don't need cleanup but I've found that expecting a
long-running db
connection to stay open is unwise. MySQL will unilaterally
abandon
connections after so many idle hours (12 or so), and if
MySQL is
restarted the connection is no longer valid either, while it
appears
open in the Quixote application until you do a query, at
which point
you get a "MySQL server has gone away" exception.
Unfortunately I
didn't realize this when I wrote a few applications, so now
I have a
cron job that restarts them every N hours as a kludge. The
proper way
would be to use a "smart reconnect" connection
from SQLAlchemy or some
other db modules. These reconnect and retry the query if
the
connection is dead.
--
Mike Orr <sluggoster gmail.com>
_______________________________________________
Quixote-users mailing list
Quixote-users mems-exchange.org
http://mail.mems-exchange.org/mailman/listinfo/quixo
te-users
|