I am going through Psycopg Connections Pooling documentation, and don’t understand what is the purpose of ‘key’ argument in getconn and putconn?
I am going through Psycopg Connections Pooling documentation, and don’t understand what is the
Share
Perusing the source code of psycopg2 (
lib/pool.py) you can see that thepsycopg2.pool.AbstractConnectionPoolclass has adictattribute named_usedwhere the connections in the pool are referenced. Thekeyparameter in thegetconnandputconnmethods is the the key to the items in that dictionary. By default, if the value of thekeyparameter of these methods isNonetheidof the connection object is used as the key.Basically the
keyparameter allows implementers of concrete connection pool classes to identify connections. For example, in thepsycopg2.pool.PersistentConnectionPoolclass, a single connection is meant to be shared in a single thread, so the thread ID is used as the key.