1
Livid MOD 出错时就让程序重连一下 MySQL 服务器。
|
2
neildd 2012-11-22 10:16:48 +08:00
是不是在多线程里调用了MySQLdb,多线程里会出这种问题。
|
3
neildd 2012-11-22 10:17:45 +08:00
import MySQLdb
class MyDBClass: def __init__(self, db_host, db_user, db_pass, db_name, db_charset='UTF8'): self.db_host = db_host self.db_user = db_user self.db_pass = db_pass self.db_name = db_name self.db_charset = db_charset self.db = None def db_connect(self): self.db = MySQLdb.connect(host=self.db_host, user=self.db_user, passwd=self.db_pass, db=self.db_name, charset=self.db_charset) self.cursor = self.db.cursor() def db_ping(self): if not self.db: self.db_connect() else: try: self.db.ping() except: self.db_connect() def db_fetchone(self, *args): self.db_ping() self.cursor.execute(*args) ret = self.cursor.fetchone() return ret def db_fetchall(self, *args): self.db_ping() self.cursor.execute(*args) ret = self.cursor.fetchall() return ret def db_execute(self, *args): self.db_ping() self.cursor.execute(*args) return self.db.insert_id() |
4
codenamea 2012-11-22 12:26:27 +08:00 1
app.config["SQLALCHEMY_POOL_RECYCLE"] = XXX 这个值比mysql里设置的略小一点。这样每次在mysql连接超时之前,sqlalchemy就会自动回收。
另外2个小时就掉了,感觉不是8小时的超时。你可以自己输出以下mysql的配置看一下。 : show variables like '%timeout'; |
5
ElmerZhang 2012-11-22 13:30:44 +08:00
报gone away时重新连接就好了
|