PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > "ping" not reconnecting in Python MySQLdb client interface
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
"ping" not reconnecting in Python MySQLdb client interface

Réponse
 
LinkBack Outils de la discussion
Vieux 03/02/2008, 08h36   #1
John Nagle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut "ping" not reconnecting in Python MySQLdb client interface

I have some long-running Python programs that can be idle
for hours, and, of course, the MySQL connection times out.
So I call

db.ping()

at the beginning of a new request cycle. This should
reestablish the connection, but it doesn't:

Traceback (most recent call last):
File "rateapiv1.fcgi", line 60, in QuickSitetruthQuery
db.ping() # reattach connection if necessary
OperationalError: (2006, 'MySQL server has gone away')

The MySQL server is up, and new connection attempts succeed.

This problem was reported two years ago relative to TurboGears:

http://trac.turbogears.org/ticket/872

I suspect that MySQL has auto-reconnect turned off, but doesn't document this.

(MySQL 5 on Fedora Core)

John Nagle
  Réponse avec citation
Vieux 03/02/2008, 17h03   #2
John Nagle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: "ping" not reconnecting in Python MySQLdb client interface

JJohn Nagle wrote:
> I have some long-running Python programs that can be idle
> for hours, and, of course, the MySQL connection times out.
> So I call
>
> db.ping()
>
> at the beginning of a new request cycle. This should
> reestablish the connection, but it doesn't.

....
> I suspect that MySQL has auto-reconnect turned off, but doesn't document
> this.


That seems to be the case. MySQLdb.connect turns off auto-reconnect, and
doesn't document "ping".

I'm currently trying this:

if db : # if previously attached
try :
db.ping() # test connection
except MySQLdb.OperationalError, message: # loss of connection
db = None # we lost database connection
if db is None : # if no valid database handle
db = MySQLdb.connect(...) # connect to database

which is a bit ugly.

John Nagle
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h39.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08070 seconds with 10 queries