Report an Issue

HappyBase Connection Pool#

Warning

gRPC is required for using the Cloud Bigtable API. As of May 2016, grpcio is only supported in Python 2.7, so importing gcloud.bigtable in other versions of Python will fail.

Google Cloud Bigtable HappyBase pool module.

class gcloud.bigtable.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.

Parameters:timeout (int) – (Optional) Time (in seconds) to wait for a connection to open.
Return type:Connection
Returns:An active connection from the pool.
Raises:NoConnectionsAvailable if no connection can be retrieved from the pool before the timeout (only if a timeout is specified).
exception gcloud.bigtable.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.