I have been trying to use connection pool for mysql in python. While searching for options, I came across MySQLConnectionPool
. It seems to work decently but I am not able to find how to achieve some of the features of MySQL.
cursorclass=MySQLdb.cursors.DictCursor
If someone knows about how to achieve this, please let me know. Thanks in advance.
I finally am able to achieve this.
Lock
module in python
. Because I am using pool for a server, I will get concurrent requests which should not alter the database for the connection pool in its entirety.For dictionary, while creating cursor I set the value of parameter dictionary
to True
.
lock.acquire()
try:
self._pool.set_config(**conn_config) //conn_config contains the modified database details
conn = self._pool.get_connection()
cursor = conn.cursor(dictionary=True)
except PoolError:
//do something
lock.release()