Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#32 Interface to set MYSQL_OPT_RECONNECT

MySQLdb
open
Andy Dustman
MySQLdb (53)
5
2012-09-19
2006-05-06
Paul Eastham
No

My hosting provider reboots their mysql database every
hour, causing my persistent mysqldb apps to crash with
"mysql server has gone away".

This patch exposes the MYSQL_OPT_RECONNECT flag in the
connect() method. You can now send a keyword argument
of "reconnect=1" to cause the mysql API to attempt to
reconnect if the connection is lost.

Discussion

1 2 > >> (Page 1 of 2)
  • Paul Eastham
    Paul Eastham
    2006-05-13

    here's the patch

     
    Attachments
  • Logged In: YES
    user_id=1530153

    Is not this patch applied yet to the latest release?

     
  • sophana
    sophana
    2006-12-27

    Logged In: YES
    user_id=931678
    Originator: NO

    This patch is not in the 1.2.2 and it should!
    It does apply correctly on 1.2.2

     
  • Charles V.
    Charles V.
    2007-05-14

    Logged In: YES
    user_id=1772693
    Originator: NO

    Is there a reason to not apply this patch ?

     
  • Logged In: YES
    user_id=49336
    Originator: NO

    why is this still not in the latest release, it's very useful to include

     
  • phatmonkey
    phatmonkey
    2007-07-24

    Logged In: YES
    user_id=1005618
    Originator: NO

    Please include! It is indeed very useful

     
  • runz
    runz
    2007-10-04

    Logged In: YES
    user_id=1903663
    Originator: NO

    there is a bug in this patch. see the lines where the reconnect option told to the server (somewhere at line 570):

    if (reconnect > 0) {
    my_bool bool = reconnect;
    mysql_options(conn, MYSQL_OPT_RECONNECT, &bool);
    }

    this if statement has to be tested against the connection (conn) like this:

    if ((reconnect > 0) && (conn)) {
    my_bool bool = reconnect;
    mysql_options(conn, MYSQL_OPT_RECONNECT, &bool);
    }

    Otherwise false parameters to connection will cause a segmentation fault at this point, because the connection doesn't exist at all.

     
  • Bernd Zeimetz
    Bernd Zeimetz
    2007-10-06

    Logged In: YES
    user_id=721761
    Originator: NO

    The developers of Zenoss modified the patch a little bit:

    • if (conn && reconnect > 0) {
    • my_bool bool = reconnect;
    • mysql_options(conn, MYSQL_OPT_RECONNECT, &bool);
    • }

    find the updated patch here:
    http://dev.zenoss.com/svn/trunk/inst/externallibs/MySQL-python-1.2.0.patch02

    Please apply to the next version,

    thanks

    Bernd

     
  • darking
    darking
    2008-10-23

    Isn't there already the option "reconnect" in the latest version?

    Close?

     
  • Andy Dustman
    Andy Dustman
    2008-10-23

    There is, as an optional argument to connection.ping().

    This is an extremely dangerous option that I'm not going to support. It's disabled in MySQL-5.0 and up for a reason: It silently reconnects to the database which rolls back any transaction you might have in progress.

    I suppose I could make it a conditional compilation option, but if you use transactions, you should never use this. Write your application to recover from errors instead.

     
1 2 > >> (Page 1 of 2)