[Zope3-dev] Re: rdb: Disappearing Connection
jürgen Kartnaller
juergen at kartnaller.at
Thu Dec 15 13:40:09 EST 2005
Dieter Maurer wrote:
> Jim Washington wrote at 2005-12-13 21:40 -0500:
>
>>...
>>Now, looking closer at the code, a ping like this might be not too bad,
>>because isConnected() is only called when a connection is requested, not
>>for every SQL statement executed. So, it might not be so onerous as
>>originally thought. Still not ideal, though.
>
>
> Be careful what you do when you find that "isConnected()" returns false.
> Note, that, in general, it would be a bug to just reopen a new connection
> in this case: previous operations against the connection might have
> been lost without notice when you simply reopen a new connection
> and do as if nothing bad had happened.
> Instead, you should reopen the connection and then raise an exception
> similar to "ZODB.POSException.ConflictError". Hopefully, the publisher
> will handle this kind of exception correctly (by retrying the complete
> request).
>
MySQL::Ping will automatically reopen a closed connection in a way where
the existing connection object can still be used.
If MySQL::Ping fails something really bad is going on.
To reduce the number of ping's in my application I used a timer which
was tested before every call to a database function.
If the timer expired I did a ping to ensure mysql is reconnected.
This is the code sqlobject is using :
while (1):
try:
return cursor.execute(query)
except MySQLdb.OperationalError, e:
if e.args[0] == 2013: # SERVER_LOST error
if self.debug:
self.printDebug(conn, str(e), 'ERROR')
else:
raise
So, checking for SERVER_LOST and then eventually using MySQL::Ping would
do the trick.
Jürgen
--
---------------------------------------------------
Jürgen Kartnaller mailto:juergen_at_kartnaller.at
http://www.kartnaller.at
http://www.mcb-bregenz.at
---------------------------------------------------
More information about the Zope3-dev
mailing list