From 3526f7f32afb917d80cc79832e3313e6b06bb7d6 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Wed, 14 Mar 2012 14:57:42 +0000
Subject: [PATCH] Auto reconnect to MySQL server

git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/trunk@498 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1
---
 mutalyzer/Db.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/mutalyzer/Db.py b/mutalyzer/Db.py
index b8a6ff9c..fbd6c91b 100644
--- a/mutalyzer/Db.py
+++ b/mutalyzer/Db.py
@@ -28,6 +28,15 @@ from mutalyzer import util
 from mutalyzer import config
 
 
+# Automatically reconnect to the MySQL server. This is expecially useful for
+# long-running processes such as the batch deamon, which would otherwise loose
+# their connection on an event such as restarting the MySQL server. Also see
+# Trac ticket #91.
+# Be alarmed though, that this messes up transactions. Fortunately, Mutalyzer
+# doesn't use transactions at the moment.
+AUTO_RECONNECT = True
+
+
 #
 # Note that compound queries are split into single queries because of a bug
 # in MySQLdb. The functions load_Update(),  merge_cdsUpdates() and
@@ -64,8 +73,8 @@ class Db() :
         @type mySqlHost: string
         """
 
-        self.__db = MySQLdb.connect(user = mySqlUser, db = dbName,
-                                    host = mySqlHost)
+        self.__db = MySQLdb.connect(user=mySqlUser, db=dbName, host=mySqlHost,
+                                    reconnect=AUTO_RECONNECT)
     #__init__
 
     def query(self, statement) :
-- 
GitLab