'What to do if you get a mysql.connector Pool Error

In Python, I used the "mysql.connector" package to implement MySQL connection pooling. Pool size is exhausted error is a problem I'm having. I've double-checked all of the connection closing parts and discovered that I'm closing database connections at each and every function, so there's very little danger of connection leakage. What is the best way to deal with the pool size exhaust issue in Python? Here is the code of the connection pool: connection.py file

from mysql.connector import pooling
CONNECTIONS = None

def set_connection():
    global CONNECTIONS
    if CONNECTIONS is None:
        CONNECTIONS = pooling.MySQLConnectionPool(
                pool_name= "dbpool",
                pool_size= 20,
                pool_reset_session=True,
                **{
                "host": "*",
                "port": "*",
                "user": "*",
                "password": "*"
            })

def pool():
    return CONNECTIONS

def close(conn, cursor):
    cursor.close()
    conn.close()



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source