DBConnectionPool

DBConnectionPool TODO

Contents

class gDBPool.gDBPool.DBConnectionPool(dsn, db_module='psycopg2', pool_size=10, conn_lifetime=600, do_log=False)[source]

Bases: object

The Connection Pool

“Classic” pool of connections with connection lifecycle management

Parameters:
  • dsn (string) – DSN for the default class:DBConnectionPool
  • db_module (string) – name of the DB-API module to use
  • pool_size (int) – Poolsize of the first/default class:DBConnectionPool
  • conn_lifetime (int) – Number of seconds after which a connection will be recycled when put() back
  • do_log (bool) – Log to the console or not
create_connection()[source]

Try to open a new connection to the database and put it on the pool

get(timeout=None, iso_level=2)[source]

Get a connection from the pool

Parameters:
  • timeout (int) – seconds to wait for a connection or None
  • iso_level – transaction isolation level to be set on the connection. Must be one of psycopg2.extensions ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ_UNCOMMITTED, ISOLATION_LEVEL_READ_COMMITTED, ISOLATION_LEVEL_REPEATABLE_READ, ISOLATION_LEVEL_SERIALIZABLE
Returns:

– a PoolConnection

put(conn, timeout=1, force_recycle=False)[source]

Put a connection back onto the pool

Parameters:
  • conn – The PoolConnection object to be put back onto the pool
  • timeout (int) – timeout in seconds to to put the connection onto the pool
  • force_recycle (bool) – Force connection recycling independent from the pool wide connection lifecycle

Table Of Contents

Previous topic

gDBPool Usage

Next topic

DBInteractionPool

This Page