[Tutor] Exceptions while dealing with MySQL

Thanos Panousis pthanos at gmail.com
Sat Apr 21 17:22:27 CEST 2007


Well, the best thing to do is to just keep on asking until the server
is up. Sending emails and other logging can be done inside whatever
wrapper function.

So if wrappers is a good way to go, how should I pursue this? Just
making my own wrapper functions or subclassing from MySQLdb?

Is it really possible that this is not a very common problem to which
others have already provided some kind of solution? Or is it just
rather easy to resolve so everyone just re-does it?

On 4/21/07, Kent Johnson <kent37 at tds.net> wrote:
> Thanos Panousis wrote:
> > Hello list,
> >
> > I am developing a network management system that relies heavily on a
> > MySQL database. The logic of the program is unavoidably coupled with
> > query results I get from various tables.
> >
> > This is OK as long the mysql server has 100% uptime, but it hardly
> > does. Say that I have to make at least 20 different kinds of queries
> > here and there in different parts of my code(all together more than a
> > thousand queries). What is the best approach to make error checking
> > possible, with the least amount of code duplication?
> >
> > Right now my code is probably ill-structured in terms of the database
> > backend. A MySQLdb.connection object is juggled around as an arguement
> > to my own program's objects, so that they can retrieve the info they
> > need from the database tables when needed. After a whole program
> > iteration has finished, the connection object is destroyed and a new
> > one is cerated for the next iteration.
> >
> > This means that a 5-minute downtime of the SQL server will cause my
> > program to crash. It is really too much trouble checking for
> > exceptions every time I make a simple query. What approach should I
> > try take?
>
> What do you want to have happen when the server is down? Should the
> program wait and retry?
>
> One possibility would be to wrap the database connection in a class
> which checks for exceptions and retries. If you are only doing queries
> (no updates) this might work OK. Or perhaps the wrapper could test for
> availability of the database before making a request.
>
> Kent
>


More information about the Tutor mailing list