[Mailman-Developers] More on Mysql MemberAdaptor?

Barry Warsaw barry at python.org
Mon Nov 10 11:36:38 EST 2003

I'm trying to catch up on this thread, so apologies if these questions
are already answered...

On Wed, 2003-11-05 at 06:11, Kyrian wrote:

> But seriously, doing it that way means I don't really have to worry
> about connection timeouts, etc. Maybe it can be rewritten later to work
> differently (like when I learn to write better python ;*), but for the
> most part, it will work now. I have cut down the number of connect()
> calls a little already though, but not as far as perhaps I could go.

I've been using the MySQLdb wrapper for Python recently in a different
project and here's how I've dealt with connection timeouts.  I have a
"doquery" method which essentially calls connection.query() with the SQL
statement.  Wrap that call in try/except for MySQLdb.OperationalError,
catch the exception object and test the error code against
MySQLdb.constants.CR.SERVER_LOST.  If they match, just chuck and re-open
the connection.  If they don't, just re-raise the exception.

Untested code example:

from MySQLdb import OperationalError
from MySQLdb.constants.CR import SERVER_LOST

    def _doquery(self, sqlcmd):
        except OperationalError, e:
             code, msg = e
             if code <> SERVER_LOST: raise

> <bounce info
> for member bounceybouncey at orenet.co.uk
>         current score: 1.0
>         last bounce date: (2003, 11, 4)
>         email notices left: 3
>         last notice date: (1970, 1, 2)
>         confirmation cookie: a9e8f042d93d3777da981f353f2e00ade42f6f 
> I'm putting the "info" parameter from setBounceInfo directly into the
> database, which I think is an array itself, not a single value, and the
> above doesn't look like Python's just traversing an array, and dumping
> it into the database(the LHS names don't tie up with what I think are
> the keys for the subelements of "info"), so it looks like I'll have to
> take a "best guess" at how to implement this.

My suggestion would be to pickle the BounceInfo object on the way into
the database, and unpickle it on the way out.


More information about the Mailman-Developers mailing list