1. 设置超时时间
import pymysql
from DBUtils.PooledDB import pooledDB
_DB_POOL_ = {}
db_dict = {
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"passwd": "123456",
"db": "utpdb",
"maxconnections": 10,
"charset": "utf8",
"setsession": ['SET AUTOCOMMIT = 1'],
"connection_timeout": 60,
"read_timeout": 60,
"write_timeout": 60,
}
def connect(db_name):
if db_name not in _DB_POOL_:
_DB_POOL_[db_name] = PooledDB(pymysql, **db_dict)
db_pool = _DB_POOL_[db_name]
return Conn(db_pool)