[Twisted-Python] Adbapi, cp_reconnect and MySQL

Hi all, quick question:
In adbapi's Transaction.reopen:
def reopen(self): if self._connection is None: self.reconnect()
if self._cursor is not None: self.close()
try: self._cursor = self._connection.cursor() return except: if not self._pool.reconnect: raise
My understand of the goal of cp_reconnect is to ensure that at the beginning of a query, the connection be re-established if it timed out since the last query (I understand that trying to reconnect in the middle of an interaction could potentially have undesired and unpredictable effects).
The code above seems to assume that self._connection.cursor() will raise ConnectionLost if the connection has timed out.
My question is two-fold: 1) should it not specifically check for ConnectionLost rather than catch everything? 2) I don't know about other backends, but MySQL will cheerfully give you a cursor object whenever you ask for one, and only raises ConnectionLost when you actually call execute on the cursor, making the code above completely ineffective. Anyone has a clever solution to this, short of inserting " self._cursor.execute(self._pool.good_sql)" in the try block? That works, but isn't exactly performance friendly...
Any help appreciated,
Yanick Dufresne Iotum Corporation
participants (1)
-
Yanick Dufresne