HappyBase Connection Pool#

Google Cloud Bigtable HappyBase pool module.

class google.cloud.happybase.pool.ConnectionPool(size, **kwargs)[source]#

Bases: object

Thread-safe connection pool.

Note

All keyword arguments are passed unmodified to the Connection constructor except for autoconnect. This is because the open / closed status of a connection is managed by the pool. In addition, if instance is not passed, the default / inferred instance is determined by the pool and then passed to each Connection that is created.

Parameters:
  • size (int) – The maximum number of concurrently open connections.
  • kwargs (dict) – Keyword arguments passed to Connection constructor.
Raises:

TypeError if size is non an integer. ValueError if size is not positive.

connection(*args, **kwds)[source]#

Obtain a connection from the pool.

Must be used as a context manager, for example:

with pool.connection() as connection:
    pass  # do something with the connection

If timeout is omitted, this method waits forever for a connection to become available from the local queue.

Yields an active Connection from the pool.

Parameters:timeout (int) – (Optional) Time (in seconds) to wait for a connection to open.
Raises:NoConnectionsAvailable if no connection can be retrieved from the pool before the timeout (only if a timeout is specified).
exception google.cloud.happybase.pool.NoConnectionsAvailable[source]#

Bases: exceptions.RuntimeError

Exception raised when no connections are available.

This happens if a timeout was specified when obtaining a connection, and no connection became available within the specified timeout.