MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / dispose

Method dispose

lib/sqlalchemy/engine/base.py:3139–3187  ·  view source on GitHub ↗

Dispose of the connection pool used by this :class:`_engine.Engine`. A new connection pool is created immediately after the old one has been disposed. The previous connection pool is disposed either actively, by closing out all currently checked-in connections in tha

(self, close: bool = True)

Source from the content-addressed store, hash-verified

3137 return "Engine(%r)" % (self.url,)
3138
3139 def dispose(self, close: bool = True) -> None:
3140 """Dispose of the connection pool used by this
3141 :class:`_engine.Engine`.
3142
3143 A new connection pool is created immediately after the old one has been
3144 disposed. The previous connection pool is disposed either actively, by
3145 closing out all currently checked-in connections in that pool, or
3146 passively, by losing references to it but otherwise not closing any
3147 connections. The latter strategy is more appropriate for an initializer
3148 in a forked Python process.
3149
3150 Event listeners associated with the old pool via :class:`.PoolEvents`
3151 are **transferred to the new pool**; this is to support the pattern
3152 by which :class:`.PoolEvents` are set up in terms of the owning
3153 :class:`.Engine` without the need to refer to the :class:`.Pool`
3154 directly.
3155
3156 :param close: if left at its default of ``True``, has the
3157 effect of fully closing all **currently checked in**
3158 database connections. Connections that are still checked out
3159 will **not** be closed, however they will no longer be associated
3160 with this :class:`_engine.Engine`,
3161 so when they are closed individually, eventually the
3162 :class:`_pool.Pool` which they are associated with will
3163 be garbage collected and they will be closed out fully, if
3164 not already closed on checkin.
3165
3166 If set to ``False``, the previous connection pool is de-referenced,
3167 and otherwise not touched in any way.
3168
3169 .. versionadded:: 1.4.33 Added the :paramref:`.Engine.dispose.close`
3170 parameter to allow the replacement of a connection pool in a child
3171 process without interfering with the connections used by the parent
3172 process.
3173
3174
3175 .. seealso::
3176
3177 :ref:`engine_disposal`
3178
3179 :ref:`pooling_multiprocessing`
3180
3181 :meth:`.ConnectionEvents.engine_disposed`
3182
3183 """
3184 if close:
3185 self.pool.dispose()
3186 self.pool = self.pool.recreate()
3187 self.dispatch.engine_disposed(self)
3188
3189 @contextlib.contextmanager
3190 def _optional_conn_ctx_manager(

Callers

nothing calls this directly

Calls 2

engine_disposedMethod · 0.80
recreateMethod · 0.45

Tested by

no test coverage detected