mysql,python应用在travis测试超时

我感觉问题出在数据库的连接部分。因为以前一直报错#2006 说mysql connection has gone away

后来我修改了下,连接的时候进行下ping,出现exception的时候新建一个连接

数据库连接部分代码:

class Database: configs = { # default configs "host": "localhost", "port": 3306, # int "db": "", "user": "", "passwd": "", "charset": "utf8" } conn = None debug = True query_times = 0 SQL = None @classmethod def configcls, debug=True, **configs: cls.configs.updateconfigs cls.debug = debug @classmethod def new_conncls: cls.conn = MySQLdb.connect cursorclass=MySQLdb.cursors.DictCursor, **cls.configs @classmethod def connectcls: # singleton if not cls.conn or not cls.conn.open: cls.new_conn try: cls.conn.ping # ping to test if the connection is working except MySQLdb.OperationalError: cls.new_conn return cls.conn

发表评论

电子邮件地址不会被公开。 必填项已用*标注