Search code examples
pythonmysqlmysql-connector-python

Ending a connection pool in mysql-connector-python


I have a connection pool that I create using mysql-connector-python:

dbconfig = {
        "database": db,
        "user":     "user"
}    
cnxpool = mysql.connector.pooling.MySQLConnectionPool(pool_name = appname,
                                  pool_size = 5,
                                  **dbconfig)

In the mysql-connector API, there doesn't appear to be a method for ending a connection pool. Is there a way to end a connection pool?


Solution

  • According to this: http://dev.mysql.com/doc/connector-python/en/connector-python-connection-pooling.html

    You can just call the close() method of the pool

    EDIT :

    As commented, this will not close the pool, it will only return the connection to the pool.

    I looked at this source code https://github.com/mysql/mysql-connector-python/blob/master/lib/mysql/connector/pooling.py

    And it looks like the only method that will do it is _remove_connections but it is intended for testing.