class Pool(log.Identified, event.EventTarget): (source)
Known subclasses: sqlalchemy.pool.impl.AssertionPool
, sqlalchemy.pool.impl.NullPool
, sqlalchemy.pool.impl.QueuePool
, sqlalchemy.pool.impl.SingletonThreadPool
, sqlalchemy.pool.impl.StaticPool
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 :class:`_pool.Pool`, of the same class as this one and configured with identical creation arguments. |
Method | status |
Undocumented |
Class Variable | dispatch |
Undocumented |
Instance Variable | echo |
Undocumented |
Instance Variable | logging |
Undocumented |
Method | _close |
Undocumented |
Method | _create |
Called by subclasses to create a new ConnectionRecord. |
Method | _creator |
Undocumented |
Method | _creator |
Undocumented |
Method | _do |
Implementation for :meth:`get`, supplied by subclasses. |
Method | _do |
Implementation for :meth:`return_conn`, supplied by subclasses. |
Method | _invalidate |
Mark all connections established within the generation of the given connection as invalidated. |
Method | _return |
Given a _ConnectionRecord, return it to the :class:`_pool.Pool`. |
Method | _should |
Detect if creator accepts a single argument, or is sent as a legacy style no-arg function. |
Instance Variable | _creator |
Undocumented |
Instance Variable | _dialect |
Undocumented |
Instance Variable | _invalidate |
Undocumented |
Instance Variable | _invoke |
Undocumented |
Instance Variable | _orig |
Undocumented |
Instance Variable | _pre |
Undocumented |
Instance Variable | _recycle |
Undocumented |
Instance Variable | _reset |
Undocumented |
Property | _creator |
Undocumented |
Property | _is |
Undocumented |
Inherited from Identified
:
Class Variable | __slots__ |
Undocumented |
Class Variable | logger |
Undocumented |
Method | _should |
Undocumented |
Method | _should |
Undocumented |
Class Variable | _echo |
Undocumented |
Union[ _CreatorFnType, _CreatorWRecFnType]
, recycle: int
= -1, echo: log._EchoFlagType
= None, logging_name: Optional[ str]
= None, reset_on_return: _ResetStyleArgType
= True, events: Optional[ List[ Tuple[ _ListenerFnType, str]]]
= None, dialect: Optional[ Union[ _ConnDialect, Dialect]]
= None, pre_ping: bool
= False, _dispatch: Optional[ _DispatchCommon[ Pool]]
= None):
(source)
¶
sqlalchemy.pool.impl.AssertionPool
, sqlalchemy.pool.impl.QueuePool
, sqlalchemy.pool.impl.SingletonThreadPool
Construct a Pool. :param creator: a callable function that returns a DB-API connection object. The function will be called with parameters. :param recycle: If 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. :param logging_name: String 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. :param 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 :func:`_sa.create_engine` call by using the :paramref:`_sa.create_engine.echo_pool` parameter. .. seealso:: :ref:`dbengine_logging` - further detail on how to configure logging. :param reset_on_return: Determine steps to take on connections as they are returned to the pool, which were not otherwise handled by a :class:`_engine.Connection`. Available from :func:`_sa.create_engine` via the :paramref:`_sa.create_engine.pool_reset_on_return` parameter. :paramref:`_pool.Pool.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. * ``"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 may be appropriate if the database / DBAPI works in pure "autocommit" mode at all times, or if a custom reset handler is established using the :meth:`.PoolEvents.reset` event handler. * ``True`` - same as 'rollback', this is here for backwards compatibility. * ``False`` - same as None, this is here for backwards compatibility. For further customization of reset on return, the :meth:`.PoolEvents.reset` event hook may be used which can perform any connection activity desired on reset. .. seealso:: :ref:`pool_reset_on_return` :meth:`.PoolEvents.reset` :param events: a list of 2-tuples, each of the form ``(callable, target)`` which will be passed to :func:`.event.listen` upon construction. Provided here so that event listeners can be assigned via :func:`_sa.create_engine` before dialect-level listeners are applied. :param dialect: a :class:`.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 :func:`_sa.create_engine` should not use this parameter as it is handled by the engine creation strategy. .. versionadded:: 1.1 - ``dialect`` is now a public parameter to the :class:`_pool.Pool`. :param 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. .. versionadded:: 1.2
sqlalchemy.pool.impl.SingletonThreadPool
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.
sqlalchemy.pool.impl.AssertionPool
, sqlalchemy.pool.impl.NullPool
, sqlalchemy.pool.impl.QueuePool
, sqlalchemy.pool.impl.SingletonThreadPool
, sqlalchemy.pool.impl.StaticPool
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. .. seealso:: :meth:`Pool.recreate`
sqlalchemy.pool.impl.AssertionPool
, sqlalchemy.pool.impl.NullPool
, sqlalchemy.pool.impl.QueuePool
, sqlalchemy.pool.impl.SingletonThreadPool
, sqlalchemy.pool.impl.StaticPool
Return a new :class:`_pool.Pool`, of the same class as this one and configured with identical creation arguments. This method is used in conjunction with :meth:`dispose` to close out an entire :class:`_pool.Pool` and create a new one in its place.
sqlalchemy.pool.impl.StaticPool
Called by subclasses to create a new ConnectionRecord.
sqlalchemy.pool.impl.AssertionPool
, sqlalchemy.pool.impl.NullPool
, sqlalchemy.pool.impl.QueuePool
, sqlalchemy.pool.impl.SingletonThreadPool
, sqlalchemy.pool.impl.StaticPool
Implementation for :meth:`get`, supplied by subclasses.
sqlalchemy.pool.impl.AssertionPool
, sqlalchemy.pool.impl.NullPool
, sqlalchemy.pool.impl.QueuePool
, sqlalchemy.pool.impl.SingletonThreadPool
, sqlalchemy.pool.impl.StaticPool
Implementation for :meth:`return_conn`, supplied by subclasses.
PoolProxiedConnection
, exception: Optional[ BaseException]
= None, _checkin: bool
= True):
(source)
¶
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.
Given a _ConnectionRecord, return it to the :class:`_pool.Pool`. This method is called when an instrumented DBAPI connection has its ``close()`` method called.
Union[ _CreatorFnType, _CreatorWRecFnType]
) -> _CreatorWRecFnType
:
(source)
¶
Detect if creator accepts a single argument, or is sent as a legacy style no-arg function.