--- a/mytoolkit/mymanager.py Mon Nov 21 10:47:24 2011 +0100
+++ b/mytoolkit/mymanager.py Fri Nov 25 18:17:27 2011 +0100
@@ -67,13 +67,12 @@
The row returned by fetchone_dict() is special dict object, which can be accessed
using item or attribute access, that is row['now'] or row.now.
+
"""
from contextlib import contextmanager
import logging
import threading
-import select
-import socket
import MySQLdb
import MySQLdb.cursors
@@ -199,7 +198,10 @@
conn = None
while len(self.conn_pool[name]) and conn is None:
conn = self.conn_pool[name].pop()
- if conn.closed:
+ try:
+ conn.ping()
+ except MySQLdb.MySQLError:
+ conn.close()
conn = None
if conn is None:
@@ -226,7 +228,11 @@
return
# connection returned to the pool must not be in transaction
- conn.rollback()
+ try:
+ conn.rollback()
+ except OperationalError:
+ conn.close()
+ return
self.conn_pool[name].append(conn)
finally:
@@ -253,7 +259,7 @@
conn = MySQLdb.connect(cursorclass=Cursor, **ci.parameters)
if not ci.isolation_level is None:
if ci.isolation_level == 'AUTOCOMMIT':
- conn.autocommit()
+ conn.autocommit(True)
else:
curs = conn.cursor()
curs.execute('SET SESSION TRANSACTION ISOLATION LEVEL ' + ci.isolation_level)