Pool
plateforme.core.database.pool
This module provides utilities for managing database pooling within the Plateforme framework using SQLAlchemy features.
NullPool
NullPool(
creator: Union[_CreatorFnType, _CreatorWRecFnType],
recycle: int = -1,
echo: _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,
)
Bases: Pool
A Pool which does not pool connections.
Instead it literally opens and closes the underlying DB-API connection per each connection open/close.
Reconnect-related functions such as recycle
and connection
invalidation are not supported by this Pool implementation, since
no connections are held persistently.
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.
: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
Source code in .venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
connect
connect() -> PoolProxiedConnection
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.
Source code in .venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py
QueuePool
QueuePool(
creator: Union[_CreatorFnType, _CreatorWRecFnType],
pool_size: int = 5,
max_overflow: int = 10,
timeout: float = 30.0,
use_lifo: bool = False,
**kw: Any,
)
Bases: Pool
A :class:_pool.Pool
that imposes a limit on the number of open connections.
:class:.QueuePool
is the default pooling implementation used for
all :class:_engine.Engine
objects, unless the SQLite dialect is
in use with a :memory:
database.
Construct a QueuePool.
:param creator: a callable function that returns a DB-API
connection object, same as that of :paramref:_pool.Pool.creator
.
:param pool_size: The size of the pool to be maintained,
defaults to 5. This is the largest number of connections that
will be kept persistently in the pool. Note that the pool
begins with no connections; once this number of connections
is requested, that number of connections will remain.
pool_size
can be set to 0 to indicate no size limit; to
disable pooling, use a :class:~sqlalchemy.pool.NullPool
instead.
:param max_overflow: The maximum overflow size of the
pool. When the number of checked-out connections reaches the
size set in pool_size, additional connections will be
returned up to this limit. When those additional connections
are returned to the pool, they are disconnected and
discarded. It follows then that the total number of
simultaneous connections the pool will allow is pool_size +
max_overflow
, and the total number of "sleeping"
connections the pool will allow is pool_size. max_overflow
can be set to -1 to indicate no overflow limit; no limit
will be placed on the total number of concurrent
connections. Defaults to 10.
:param timeout: The number of seconds to wait before giving up on returning a connection. Defaults to 30.0. This can be a float but is subject to the limitations of Python time functions which may not be reliable in the tens of milliseconds.
:param use_lifo: use LIFO (last-in-first-out) when retrieving connections instead of FIFO (first-in-first-out). Using LIFO, a server-side timeout scheme can reduce the number of connections used during non-peak periods of use. When planning for server-side timeouts, ensure that a recycle or pre-ping strategy is in use to gracefully handle stale connections.
.. versionadded:: 1.3
.. seealso::
:ref:`pool_use_lifo`
:ref:`pool_disconnects`
:param **kw: Other keyword arguments including
:paramref:_pool.Pool.recycle
, :paramref:_pool.Pool.echo
,
:paramref:_pool.Pool.reset_on_return
and others are passed to the
:class:_pool.Pool
constructor.
Source code in .venv/lib/python3.12/site-packages/sqlalchemy/pool/impl.py
connect
connect() -> PoolProxiedConnection
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.
Source code in .venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py
SingletonThreadPool
SingletonThreadPool(
creator: Union[_CreatorFnType, _CreatorWRecFnType],
pool_size: int = 5,
**kw: Any,
)
Bases: Pool
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
.
Source code in .venv/lib/python3.12/site-packages/sqlalchemy/pool/impl.py
dispose
Dispose of this pool.
Source code in .venv/lib/python3.12/site-packages/sqlalchemy/pool/impl.py
StaticPool
StaticPool(
creator: Union[_CreatorFnType, _CreatorWRecFnType],
recycle: int = -1,
echo: _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,
)
Bases: Pool
A Pool of exactly one connection, used for all requests.
Reconnect-related functions such as recycle
and connection
invalidation (which is also used to support auto-reconnect) are only
partially supported right now and may not yield good results.
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.
: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
Source code in .venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
connect
connect() -> PoolProxiedConnection
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.