class documentation

class Pool(log.Identified):

View In Hierarchy

Abstract base class for connection pools.
Method __init__ Construct a Pool.
Method connect Return a DBAPI connection from the pool.
Method dispose Dispose of this pool.
Method recreate Return a new _pool.Pool, of the same class as this one and configured with identical creation arguments.
Method ​_close​_connection Undocumented
Method ​_create​_connection Called by subclasses to create a new ConnectionRecord.
Method ​_creator.setter Undocumented
Method ​_do​_get Implementation for get, supplied by subclasses.
Method ​_do​_return​_conn Implementation for return_conn, supplied by subclasses.
Method ​_invalidate Mark all connections established within the generation of the given connection as invalidated.
Method ​_return​_conn Given a _ConnectionRecord, return it to the _pool.Pool.
Method ​_should​_wrap​_creator Detect if creator accepts a single argument, or is sent as a legacy style no-arg function.
Method status Undocumented
Instance Variable ​_dialect Undocumented
Instance Variable ​_invalidate​_time Undocumented
Instance Variable ​_invoke​_creator Undocumented
Instance Variable ​_orig​_logging​_name Undocumented
Instance Variable ​_pre​_ping Undocumented
Instance Variable ​_recycle Undocumented
Instance Variable ​_reset​_on​_return Undocumented
Instance Variable echo Undocumented
Instance Variable logging​_name Undocumented
Property ​_creator Undocumented
Property ​_is​_asyncio Undocumented

Inherited from Identified:

Method ​_should​_log​_debug Undocumented
Method ​_should​_log​_info Undocumented
def __init__(self, creator, recycle=-1, echo=None, logging_name=None, reset_on_return=True, events=None, dialect=None, pre_ping=False, _dispatch=None):
Construct a Pool.
Parameters
creatora callable function that returns a DB-API connection object. The function will be called with parameters.
recycleIf set to a value other than -1, number of seconds between connection recycling, which means upon checkout, if this timeout is surpassed the connection will be closed and replaced with a newly opened connection. Defaults to -1.
echo

if True, the connection pool will log informational output such as when connections are invalidated as well as when connections are recycled to the default log handler, which defaults to sys.stdout for output.. If set to the string "debug", the logging will include pool checkouts and checkins.

The :paramref:`_pool.Pool.echo` parameter can also be set from the _sa.create_engine call by using the :paramref:`_sa.create_engine.echo_pool` parameter.

See Also

:ref:`dbengine_logging` - further detail on how to configure logging.

logging​_nameString identifier which will be used within the "name" field of logging records generated within the "sqlalchemy.pool" logger. Defaults to a hexstring of the object's id.
reset​_on​_return
Determine steps to take on

connections as they are returned to the pool, which were not otherwise handled by a _engine.Connection.

reset_on_return can have any of these values:

  • "rollback" - call rollback() on the connection, to release locks and transaction resources. This is the default value. The vast majority of use cases should leave this value set.
  • True - same as 'rollback', this is here for backwards compatibility.
  • "commit" - call commit() on the connection, to release locks and transaction resources. A commit here may be desirable for databases that cache query plans if a commit is emitted, such as Microsoft SQL Server. However, this value is more dangerous than 'rollback' because any data changes present on the transaction are committed unconditionally.
  • None - don't do anything on the connection. This setting is only appropriate if the database / DBAPI works in pure "autocommit" mode at all times, or if the application uses the _engine.Engine with consistent connectivity patterns. See the section :ref:`pool_reset_on_return` for more details.
  • False - same as None, this is here for backwards compatibility.
eventsa list of 2-tuples, each of the form (callable, target) which will be passed to .event.listen upon construction. Provided here so that event listeners can be assigned via _sa.create_engine before dialect-level listeners are applied.
dialect

a .Dialect that will handle the job of calling rollback(), close(), or commit() on DBAPI connections. If omitted, a built-in "stub" dialect is used. Applications that make use of _sa.create_engine should not use this parameter as it is handled by the engine creation strategy.

New in version 1.1: - dialect is now a public parameter to the _pool.Pool.
pre​_ping

if True, the pool will emit a "ping" (typically "SELECT 1", but is dialect-specific) on the connection upon checkout, to test if the connection is alive or not. If not, the connection is transparently re-connected and upon success, all other pooled connections established prior to that timestamp are invalidated. Requires that a dialect is passed as well to interpret the disconnection error.

New in version 1.2.
​_dispatchUndocumented
def connect(self):

Return a DBAPI connection from the pool.

The connection is instrumented such that when its close() method is called, the connection will be returned to the pool.

def dispose(self):

Dispose of this pool.

This method leaves the possibility of checked-out connections remaining open, as it only affects connections that are idle in the pool.

See Also

Pool.recreate

def recreate(self):

Return a new _pool.Pool, of the same class as this one and configured with identical creation arguments.

This method is used in conjunction with dispose to close out an entire _pool.Pool and create a new one in its place.

def _close_connection(self, connection):

Undocumented

def _create_connection(self):
Called by subclasses to create a new ConnectionRecord.
@_creator.setter
def _creator(self, creator):

Undocumented

def _do_get(self):
Implementation for get, supplied by subclasses.
def _do_return_conn(self, conn):
Implementation for return_conn, supplied by subclasses.
def _invalidate(self, connection, exception=None, _checkin=True):

Mark all connections established within the generation of the given connection as invalidated.

If this pool's last invalidate time is before when the given connection was created, update the timestamp til now. Otherwise, no action is performed.

Connections with a start time prior to this pool's invalidation time will be recycled upon next checkout.

def _return_conn(self, record):

Given a _ConnectionRecord, return it to the _pool.Pool.

This method is called when an instrumented DBAPI connection has its close() method called.

def _should_wrap_creator(self, creator):
Detect if creator accepts a single argument, or is sent as a legacy style no-arg function.
def status(self):

Undocumented

_dialect =

Undocumented

_invalidate_time =

Undocumented

_invoke_creator =

Undocumented

_orig_logging_name =

Undocumented

_pre_ping =

Undocumented

_recycle =

Undocumented

_reset_on_return =

Undocumented

echo =

Undocumented

logging_name =
@property
_creator =

Undocumented

@util.hybridproperty
_is_asyncio =

Undocumented