class documentation

class SingletonThreadPool(Pool): (source)

View In Hierarchy

A Pool that maintains one connection per thread. Maintains one connection per each thread, never moving a connection to a thread other than the one which it was created in. .. warning:: the :class:`.SingletonThreadPool` will call ``.close()`` on arbitrary connections that exist beyond the size setting of ``pool_size``, e.g. if more unique **thread identities** than what ``pool_size`` states are used. This cleanup is non-deterministic and not sensitive to whether or not the connections linked to those thread identities are currently in use. :class:`.SingletonThreadPool` may be improved in a future release, however in its current status it is generally used only for test scenarios using a SQLite ``:memory:`` database and is not recommended for production use. Options are the same as those of :class:`_pool.Pool`, as well as: :param pool_size: The number of threads in which to maintain connections at once. Defaults to five. :class:`.SingletonThreadPool` is used by the SQLite dialect automatically when a memory-based database is used. See :ref:`sqlite_toplevel`.

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
Instance Variable size Undocumented
Method _cleanup Undocumented
Method _do_get Implementation for :meth:`get`, supplied by subclasses.
Method _do_return_conn Implementation for :meth:`return_conn`, supplied by subclasses.
Class Variable _is_asyncio Undocumented
Instance Variable _all_conns Undocumented
Instance Variable _conn Undocumented
Instance Variable _fairy Undocumented

Inherited from Pool:

Class Variable dispatch Undocumented
Instance Variable echo Undocumented
Instance Variable logging_name Undocumented
Method _close_connection Undocumented
Method _create_connection Called by subclasses to create a new ConnectionRecord.
Method _creator.deleter Undocumented
Method _creator.setter Undocumented
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 :class:`_pool.Pool`.
Method _should_wrap_creator Detect if creator accepts a single argument, or is sent as a legacy style no-arg function.
Instance Variable _creator_arg 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
Property _creator Undocumented

Inherited from Identified (via Pool):

Class Variable __slots__ Undocumented
Class Variable logger Undocumented
Method _should_log_debug Undocumented
Method _should_log_info Undocumented
Class Variable _echo Undocumented
def __init__(self, creator: Union[_CreatorFnType, _CreatorWRecFnType], pool_size: int = 5, **kw: Any): (source)

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

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): (source)

Dispose of this pool.

def recreate(self) -> SingletonThreadPool: (source)

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.

def status(self) -> str: (source)

Undocumented

Undocumented

def _cleanup(self): (source)

Undocumented

def _do_get(self) -> ConnectionPoolEntry: (source)

Implementation for :meth:`get`, supplied by subclasses.

def _do_return_conn(self, record: ConnectionPoolEntry): (source)

Implementation for :meth:`return_conn`, supplied by subclasses.

Undocumented

Undocumented

Undocumented