Prøv at samle forbindelser
Fra officielle dokumenter:
Ved at implementere forbindelsespooling kan du genbruge eksisterende forbindelser
dbconfig = {
"database": "test",
"user": "joe"
}
cnxpool = mysql.connector.connect(pool_name = "mypool",
pool_size = 3, # or any number to suit your need
**dbconfig)
# then to get a connection from pool use
cnx = cnxpool.get_connection()
For mere se:https://dev .mysql.com/doc/connector-python/en/connector-python-connection-pooling.html