连接池介绍
官方网站介绍:https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnectionpool.html
PooledMySQLConnection、MySQLConnectionPool、MySQLConnection三者的关系:
MySQLConnectionPool的 add_connection 方法会把连接(MySQLConnection的实例)会放入连接池中(MySQLConnectionPool的实例)。
MySQLConnectionPool的 get_connection 方法会把连接池中的连接池化,返回PooledMySQLConnection实例。
pcnx = PooledMySQLConnection(cnxpool, cnx)
# cnxpool: A MySQLConnectionPool instance.
# cnx: A MySQLConnection instance.
所以,通过(MySQLConnectionPool 的) get_connection 方法得到的连接不是 MySQLConnection 的实例,而是 PooledMySQLConnection 实例。PooledMySQLConnection 的 close