Interface to set MYSQL_OPT_RECONNECT
MySQL database connector for Python programming
Brought to you by:
adustman
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.
here's the patch
Logged In: YES
user_id=1530153
Is not this patch applied yet to the latest release?
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
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
Logged In: YES
user_id=1005618
Originator: NO
Please include! It is indeed very useful
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.
Logged In: YES
user_id=721761
Originator: NO
The developers of Zenoss modified the patch a little bit:
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
Isn't there already the option "reconnect" in the latest version?
Close?
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.
Your patch will not be applied.