Files
aitsc/.venv/Lib/site-packages/sqlalchemy/pool/__pycache__/base.cpython-312.pyc

482 lines
55 KiB
Plaintext
Raw Normal View History

2025-02-23 09:07:52 +08:00
<EFBFBD>
2025-08-29 00:34:40 +08:00
<00><19>h<EFBFBD><68><00><01>B<00>UdZddlmZddlmZddlZddlmZddlZddl Z ddl
2025-02-23 09:07:52 +08:00
Z
ddl
m Z ddl
m Z ddl
m Z dd l
mZdd
l
mZdd l
mZdd l
mZdd l
mZddl
mZddl
2025-08-29 00:34:40 +08:00
mZddlZddlmZddlmZddlmZddlmZddlmZddlmZer*ddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddl%m&Z&ejNd<1E><1F>Gd <20>d!<21><00>Z(Gd"<22>d#e<07>Z)ee)ed$fZ*e+e)<29>\Z,Z-Z.Gd%<25>d&<26>Z/Gd'<27>d(e/<2F>Z0Gd)<29>d*e<1D>Z1Gd+<2B>d,e<1D>Z2Gd-<2D>d.ejfejh<00>Z5Gd/<2F>d0<64>Z6Gd1<64>d2e6<65>Z7Gd3<64>d4e7<65>Z8 d> d?d5<64>Z9iZ:d6e;d7<Gd8<64>d9e6<65>Z<Gd:<3A>d;e<<3C>Z=Gd<<3C>d=e<<3C>Z>y)@z%Base constructs for connection pools.<2E>)<01> annotations)<01>dequeN)<01>Enum)<01>Any)<01>Callable)<01>cast)<01>Deque)<01>Dict)<01>List)<01>Optional)<01>Tuple)<01> TYPE_CHECKING)<01>Union<6F>)<01>event)<01>exc)<01>log)<01>util)<01>Literal)<01>Protocol)<01>DBAPIConnection)<01> DBAPICursor)<01>Dialect)<01>_DispatchCommon)<01>_ListenerFnType)<01>
2025-02-23 09:07:52 +08:00
dispatcher)<01> _InfoTypeT)<01>frozenc<01>8<00>eZdZUdZdZded< ded< ded<y)<08>PoolResetStatez<65>describes the state of a DBAPI connection as it is being passed to
the :meth:`.PoolEvents.reset` connection pool event.
.. versionadded:: 2.0.0b3
<20><03>transaction_was_reset<65>terminate_only<6C> asyncio_safe<66>boolr"r#r$N)<06>__name__<5F>
2025-08-29 00:34:40 +08:00
__module__<EFBFBD> __qualname__<5F>__doc__<5F> __slots__<5F>__annotations__<5F><00><00>AD:\pythonpj\aitsc\.venv\Lib\site-packages\sqlalchemy/pool/base.pyr r 0s4<00><00><08>L<01>I<EFBFBD><1F><1F>
2025-02-23 09:07:52 +08:00
<08><19><18> <08><17><16>r-r c<01><00>eZdZdZdZdZdZy)<06>
ResetStylez1Describe options for "reset on return" behaviors.r<00>rN)r&r'r(r)<00>reset_rollback<63> reset_commit<69>
2025-08-29 00:34:40 +08:00
reset_noner,r-r.r0r0]s<00><00>;<3B><16>N<EFBFBD><14>L<EFBFBD><12>Jr-r0)TNF<4E>commit<69>rollbackc<01>H<00>eZdZdZdZdZd
2025-02-23 09:07:52 +08:00
d<03>Zd
d<04>Zd d<05>Zd d<06>Z d d<07>Z
d d<08>Z y )<0E> _ConnDialectz<74>partial implementation of :class:`.Dialect`
which provides DBAPI connection methods.
When a :class:`_pool.Pool` is combined with an :class:`_engine.Engine`,
the :class:`_engine.Engine` replaces this with its own
:class:`.Dialect`.
2025-08-29 00:34:40 +08:00
Fc<01>$<00>|j<00>y<00>N)r6<00><02>self<6C>dbapi_connections r.<00> do_rollbackz_ConnDialect.do_rollbackys<00><00><18>!<21>!<21>#r-c<01>$<00>|j<00>yr:)r5r;s r.<00> do_commitz_ConnDialect.do_commit|s<00><00><18><1F><1F>!r-c<01>$<00>|j<00>yr:<00><01>closer;s r.<00> do_terminatez_ConnDialect.do_terminate<00><00><00><18><1E><1E> r-c<01>$<00>|j<00>yr:rBr;s r.<00>do_closez_ConnDialect.do_close<73>rEr-c<01><00>td<01><00>)NzJThe ping feature requires that a dialect is passed to the connection pool.<2E><01>NotImplementedErrorr;s r.<00>_do_ping_w_eventz_ConnDialect._do_ping_w_event<6E>s<00><00>!<21> -<2D>
2025-02-23 09:07:52 +08:00
<EFBFBD>
r-c<01><00>|Sr:r,)r<<00>
2025-08-29 00:34:40 +08:00
connections r.<00>get_driver_connectionz"_ConnDialect.get_driver_connection<6F>s<00><00><19>r-N)r=<00>PoolProxiedConnection<6F>return<72>None)r=rrPrQ)r=rrPr%)rMrrPr) r&r'r(r)<00>is_async<6E> has_terminater>r@rDrGrKrNr,r-r.r8r8ls1<00><00><08><15>H<EFBFBD><19>M<EFBFBD>$<24>"<22>!<21>!<21>
<EFBFBD> r-r8c<01><00>eZdZdZy)<03>_AsyncConnDialectTN)r&r'r(rRr,r-r.rUrU<00>s<00><00><13>Hr-rUc<01><00>eZdZdd<01>Zy)<04>_CreatorFnTypec<01><00>yr:r,<00>r<s r.<00>__call__z_CreatorFnType.__call__<5F>s<00><00>3r-N<>rPr<00>r&r'r(rZr,r-r.rWrW<00>s<00><00>.r-rWc<01><00>eZdZdd<01>Zy)<04>_CreatorWRecFnTypec<01><00>yr:r,<00>r<<00>recs r.rZz_CreatorWRecFnType.__call__<5F>s<00><00>Sr-N)ra<00>ConnectionPoolEntryrPrr\r,r-r.r^r^<00>s<00><00>Hr-r^c<01><><00>eZdZUdZded<ded<ded<e<05>Zded <d
2025-02-23 09:07:52 +08:00
ed <d ed <ded< d# d$d<12>Zejd%d<13><04>Z
e d&d<14><04>Z e j d'd<15><04>Z e jd(d<16><04>Z d)d<17>Zdd<18> d*d<19>Zd+d<1A>Z d, d-d<1B>Zd.d<1C>Zd(d<1D>Zd/d<1E>Zd0d<1F>Zd+d <20>Zd0d!<21>Zd1d"<22>Zy)2<>Poolz)Abstract base class for connection pools.zdispatcher[Pool]<5D>dispatch<63>log._EchoFlagType<70>echo<68> Optional[str]<5D>_orig_logging_namezUnion[_ConnDialect, Dialect]<5D>_dialect<63>)Union[_CreatorFnType, _CreatorWRecFnType]<5D> _creator_argr^<00>_invoke_creator<6F>float<61>_invalidate_timeNFc
<01><><00>|r|x|_|_nd|_tj||<03><02>||_||_d|_||_tj|tjddgtjgd<06>tjdgid<08>|_||_| r|j j#| d <09>
<EFBFBD>|r||_|r"|D]\}
} t'j(|| |
<EFBFBD><00>yy) a4
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
2025-08-29 00:34:40 +08:00
N)<01>echoflagrr6T)<03>noneNFr5<00>reset_on_returnF)<01>only_propagate)<15> logging_namerir<00>instance_logger<65>_creator<6F>_recyclero<00> _pre_pingr<00>parse_user_argument_for_enumr0r2r4r3<00>_reset_on_returnrgre<00>_updaterjr<00>listen) r<<00>creator<6F>recyclergrurs<00>events<74>dialect<63>pre_ping<6E> _dispatch<63>fn<66>targets r.<00>__init__z Pool.__init__<5F>s<><00><00>X <18>:F<> F<>D<EFBFBD> <1D><04> 7<>&*<2A>D<EFBFBD> #<23> <0B><1B><1B>D<EFBFBD>4<EFBFBD>0<><1F><04> <0A><1F><04> <0A> !<21><04><1D>!<21><04><0E> $<24> A<> A<> <1B><1A>)<29>)<29>J<EFBFBD><04>+=<3D><1A>%<25>%<25>'<<3C><1A>'<27>'<27>(<28><1A> <0E>
2025-02-23 09:07:52 +08:00
<1E>!
<EFBFBD><04><1D><19><04> <09> <14> <10>M<EFBFBD>M<EFBFBD> !<21> !<21>)<29>E<EFBFBD> !<21> B<> <12>#<23>D<EFBFBD>M<EFBFBD> <11>$<24>
2025-08-29 00:34:40 +08:00
<EFBFBD><02>F<EFBFBD><15> <0C> <0C>T<EFBFBD>6<EFBFBD>2<EFBFBD>.<2E>%<25> r-c<01>.<00>|jjSr:)rjrRrYs r.<00> _is_asynciozPool._is_asyncio1s<00><00><13>}<7D>}<7D>%<25>%<25>%r-c<01><00>|jSr:)rlrYs r.rwz Pool._creator5s<00><00><13> <20> <20> r-c<01>><00>||_|j|<01>|_yr:)rl<00>_should_wrap_creatorrm)r<r~s r.rwz Pool._creator9s!<00><00>$<24><04><19> $<24>8<>8<><17>A<><04>r-c<01> <00>|`|`yr:)rlrmrYs r.rwz Pool._creatorCs<00><00> <11> <1D> <10> r-c<01><><00><05> tj|jd<01><02>}|j <00>t|j <00>}nd}t|d<00>|z
2025-02-23 09:07:52 +08:00
}|d|dfdgdfk(rt t|<01>S|dk(rt t|<01>St t
|<01><00><05>fd <09>S#t$rt t
|<01><00><05>fd<03>cYSwxYw)
zlDetect if creator accepts a single argument, or is sent
as a legacy style no-arg function.
T)<01>no_selfc<01><00><01><00><01>Sr:r,<00>ra<00>
2025-08-29 00:34:40 +08:00
creator_fns <20>r.<00><lambda>z+Pool._should_wrap_creator.<locals>.<lambda>U<00><00><><00>z<EFBFBD>|r-r<00><00>connection_recordr:r1c<01><00><01><00><01>Sr:r,r<>s <20>r.r<>z+Pool._should_wrap_creator.<locals>.<lambda>hr<>r-) r<00>get_callable_argspecrw<00> TypeErrorrrW<00>defaults<74>lenr^)r<r~<00>argspec<65> defaulted<65> positionalsr<73>s @r.r<>zPool._should_wrap_creatorIs<><00><><00> ,<2C><1A>/<2F>/<2F><04> <0A> <0A>t<EFBFBD>L<>G<EFBFBD>
2025-02-23 09:07:52 +08:00
<13> <1B> <1B> '<27><1B>G<EFBFBD>,<2C>,<2C>-<2D>I<EFBFBD><19>I<EFBFBD><19>'<27>!<21>*<2A>o<EFBFBD> <09>1<> <0B> <14>A<EFBFBD>J<EFBFBD><07><01>
<EFBFBD> #<23>)<<3C>(=<3D>w<EFBFBD>'G<> G<><17>*<2A>G<EFBFBD>4<> 4<> <18>A<EFBFBD> <1D><17>*<2A>G<EFBFBD>4<> 4<><1E>n<EFBFBD>g<EFBFBD>6<>J<EFBFBD>+<2B> +<2B><>+<19> ,<2C><1D>n<EFBFBD>g<EFBFBD>6<>J<EFBFBD>+<2B> +<2B> ,<2C>s<00>!B#<00>#C<03>C<03><01> terminatec<01>T<00>|jjd|rdnd|<01> |r|jj|<01>y|jj |<01>y#t
$rA}|jj d|rdnd<06>d<07>|d<08> <09>t|t<00>s<01>Yd}~yd}~wwxYw)
Nz%s connection %rz Hard-closing<6E>Closingz
Exception <20> terminating<6E>closingz connection %rT<72><01>exc_info) <09>logger<65>debugrjrDrG<00> BaseException<6F>error<6F>
2025-08-29 00:34:40 +08:00
isinstance<EFBFBD> Exception)r<rMr<><00>es r.<00>_close_connectionzPool._close_connectionjs<><00><00> <0A> <0B> <0B><19><19> <1E>'<27>N<EFBFBD>Y<EFBFBD> <16>
2025-02-23 09:07:52 +08:00
<EFBFBD>
2025-08-29 00:34:40 +08:00
<16><18><14> <0A> <0A>*<2A>*<2A>:<3A>6<><14> <0A> <0A>&<26>&<26>z<EFBFBD>2<><32><1C> <16> <10>K<EFBFBD>K<EFBFBD> <1D> <1D><1C>i<EFBFBD>]<5D>Y<EFBFBD>G<>H <20>!<21><1A><1D> <1E> <0E> <1E>a<EFBFBD><19>+<2B><15>,<2C><> <16>s<00>A<00>A<00> B'<03>&7B"<03>"B'c<01><00>t|<00>S)z6Called by subclasses to create a new ConnectionRecord.)<01>_ConnectionRecordrYs r.<00>_create_connectionzPool._create_connection<6F>s<00><00>!<21><14>&<26>&r-c<01><><00>t|dd<02>}|r|j|jkrtj<00>|_|r t|dd<04>r|j |<02>yyy)a<>Mark all connections established within the generation
2025-02-23 09:07:52 +08:00
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.
<20>_connection_recordN<64>is_validF)<05>getattrro<00> starttime<6D>time<6D>
2025-08-29 00:34:40 +08:00
invalidate)r<rM<00> exception<6F>_checkinras r.<00> _invalidatezPool._invalidate<74>sX<00><00> <16>j<EFBFBD>"6<><04>=<3D><03><12>d<EFBFBD>+<2B>+<2B>c<EFBFBD>m<EFBFBD>m<EFBFBD>;<3B>$(<28>I<EFBFBD>I<EFBFBD>K<EFBFBD>D<EFBFBD> !<21> <13><07>
2025-02-23 09:07:52 +08:00
<EFBFBD>J<EFBFBD><05>><3E> <16> !<21> !<21>)<29> ,<2C>?<3F>8r-c<01><00>t<00><00>)a"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.
2025-08-29 00:34:40 +08:00
rIrYs r.<00>recreatez Pool.recreate<74>s <00><00>"<22>#<23>#r-c<01><00>t<00><00>)z<>Dispose of this pool.
2025-02-23 09:07:52 +08:00
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`
2025-08-29 00:34:40 +08:00
rIrYs r.<00>disposez Pool.dispose<73><00> <00><00>"<22>#<23>#r-c<01>,<00>tj|<00>S)z<>Return a DBAPI connection from the pool.
2025-02-23 09:07:52 +08:00
The connection is instrumented such that when its
``close()`` method is called, the connection will be returned to
the pool.
2025-08-29 00:34:40 +08:00
)<02>_ConnectionFairy<72> _checkoutrYs r.<00>connectz Pool.connect<63>s<00><00> <20>)<29>)<29>$<24>/<2F>/r-c<01>&<00>|j|<01>y)z<>Given a _ConnectionRecord, return it to the :class:`_pool.Pool`.
2025-02-23 09:07:52 +08:00
This method is called when an instrumented DBAPI connection
has its ``close()`` method called.
2025-08-29 00:34:40 +08:00
N)<01>_do_return_conn<6E>r<<00>records r.<00> _return_connzPool._return_conn<6E>s<00><00> <0A><1C><1C>V<EFBFBD>$r-c<01><00>t<00><00>)z7Implementation for :meth:`get`, supplied by subclasses.rIrYs r.<00>_do_getz Pool._do_get<65><00> <00><00>"<22>#<23>#r-c<01><00>t<00><00>)z?Implementation for :meth:`return_conn`, supplied by subclasses.rIr<>s r.r<>zPool._do_return_conn<6E>r<>r-c<01><00>t<00><00>)z6Returns a brief description of the state of this pool.rIrYs r.<00>statusz Pool.status<75><00> <00><00>!<21>#<23>#r-)<08><><EFBFBD><EFBFBD><EFBFBD>NNTNNFN)r~rkr<00>intrgrfrurhrs<00>_ResetStyleArgTyper<65>z+Optional[List[Tuple[_ListenerFnType, str]]]r<>z&Optional[Union[_ConnDialect, Dialect]]r<>r%r<>zOptional[_DispatchCommon[Pool]]<5D>rPr%)rPrk)r~rkrPrQ<00>rPrQ)r~rkrPr^)rMrr<>r%rPrQ)rPrb<00>NT)rMrOr<><00>Optional[BaseException]r<>r%rPrQ)rPrd)rPrO)r<>rbrPrQ)rP<00>str)r&r'r(r)r+r8rjr<>r<00>hybridpropertyr<79><00>propertyrw<00>setter<65>deleterr<72>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r,r-r.rdrd<00>s<><00><00>3<><1E><1E>
2025-02-23 09:07:52 +08:00
<1B><1B>%<25>%<25>-9<>^<5E>H<EFBFBD>*<2A>;<3B>;<3B>;<3B>'<27>'<27><1B><1B>
<1A>"&<26>&*<2A>.2<EFBFBD>>B<>:><3E><1E>59<35>H/<2F>:<3A>H/<2F><15>H/<2F> <20> H/<2F>
$<24> H/<2F> ,<2C> H/<2F><<3C>H/<2F>8<>H/<2F><17>H/<2F>3<>H/<2F>T
<EFBFBD><18><18>&<26><19>&<26><0E>!<21><0E>!<21><0E>_<EFBFBD>_<EFBFBD>B<01>@<40>B<01> <0A>B<01><15>B<01><0E><15><15>!<21><16>!<21>
,<2C>@<40>,<2C> <1B>,<2C>DAF<01><16>)<29><16>9=<3D><16> <0A><16>.'<27>.2<EFBFBD><1D> -<2D>)<29>-<2D>+<2B>-<2D><17> -<2D>
<0E> -<2D>,
$<24> $<24>0<>%<25>$<24>
$<24>
2025-08-29 00:34:40 +08:00
$r-rdc<01><><00>eZdZUdZdZded< ded< ejd d<07><04>Zejd d<08><04>Z d dd
2025-02-23 09:07:52 +08:00
<EFBFBD>Z
y )<0F>ManagesConnectiona3Common base for the two connection-management interfaces
:class:`.PoolProxiedConnection` and :class:`.ConnectionPoolEntry`.
These two objects are typically exposed in the public facing API
via the connection pool event hooks, documented at :class:`.PoolEvents`.
.. versionadded:: 2.0
r,<00>Optional[DBAPIConnection]r=<00> Optional[Any]<5D>driver_connectionc<01><00>t<00><00>)a<>Info dictionary associated with the underlying DBAPI connection
referred to by this :class:`.ManagesConnection` instance, allowing
user-defined data to be associated with the connection.
The data in this dictionary is persistent for the lifespan
of the DBAPI connection itself, including across pool checkins
and checkouts. When the connection is invalidated
and replaced with a new one, this dictionary is cleared.
For a :class:`.PoolProxiedConnection` instance that's not associated
with a :class:`.ConnectionPoolEntry`, such as if it were detached, the
attribute returns a dictionary that is local to that
:class:`.ConnectionPoolEntry`. Therefore the
:attr:`.ManagesConnection.info` attribute will always provide a Python
dictionary.
.. seealso::
:attr:`.ManagesConnection.record_info`
2025-08-29 00:34:40 +08:00
rIrYs r.<00>infozManagesConnection.infos <00><00>0"<22>#<23>#r-c<01><00>t<00><00>)a<>Persistent info dictionary associated with this
2025-02-23 09:07:52 +08:00
:class:`.ManagesConnection`.
Unlike the :attr:`.ManagesConnection.info` dictionary, the lifespan
of this dictionary is that of the :class:`.ConnectionPoolEntry`
which owns it; therefore this dictionary will persist across
reconnects and connection invalidation for a particular entry
in the connection pool.
For a :class:`.PoolProxiedConnection` instance that's not associated
with a :class:`.ConnectionPoolEntry`, such as if it were detached, the
attribute returns None. Contrast to the :attr:`.ManagesConnection.info`
dictionary which is never None.
.. seealso::
:attr:`.ManagesConnection.info`
2025-08-29 00:34:40 +08:00
rIrYs r.<00> record_infozManagesConnection.record_info*s <00><00>,"<22>#<23>#r-Nc<01><00>t<00><00>)aOMark the managed connection as invalidated.
2025-02-23 09:07:52 +08:00
:param e: an exception object indicating a reason for the invalidation.
:param soft: if True, the connection isn't closed; instead, this
connection will be recycled on next checkout.
.. seealso::
:ref:`pool_connection_invalidation`
2025-08-29 00:34:40 +08:00
rI<00>r<r<><00>softs r.r<>zManagesConnection.invalidateBs <00><00> "<22>#<23>#r-<00>rPr<00>rPzOptional[_InfoType]<5D>NF<4E>r<>r<>r<>r%rPrQ) r&r'r(r)r*r+r<00>ro_memoized_propertyr<79>r<>r<>r,r-r.r<>r<><00>s}<00><00><08><13>I<EFBFBD>/<2F>/<2F><08>(%<25>$<24><08>(
2025-02-23 09:07:52 +08:00
<EFBFBD><1E><1E>$<24><1F>$<24>2
2025-08-29 00:34:40 +08:00
<EFBFBD><1E><1E>$<24><1F>$<24>0?D<01>$<24>(<28>$<24>7;<3B>$<24> <0A>$r-r<>c<01>.<00>eZdZdZdZedd<03><04>Zdd<04>Zy)rbaInterface for the object that maintains an individual database
2025-02-23 09:07:52 +08:00
connection on behalf of a :class:`_pool.Pool` instance.
The :class:`.ConnectionPoolEntry` object represents the long term
maintainance of a particular connection for a pool, including expiring or
invalidating that connection to have it replaced with a new one, which will
continue to be maintained by that same :class:`.ConnectionPoolEntry`
instance. Compared to :class:`.PoolProxiedConnection`, which is the
short-term, per-checkout connection manager, this object lasts for the
lifespan of a particular "slot" within a connection pool.
The :class:`.ConnectionPoolEntry` object is mostly visible to public-facing
API code when it is delivered to connection pool event hooks, such as
:meth:`_events.PoolEvents.connect` and :meth:`_events.PoolEvents.checkout`.
.. versionadded:: 2.0 :class:`.ConnectionPoolEntry` provides the public
facing interface for the :class:`._ConnectionRecord` internal class.
2025-08-29 00:34:40 +08:00
r,c<01><00>t<00><00>)z3Return True the connection is currently checked outrIrYs r.<00>in_usezConnectionPoolEntry.in_usels <00><00>"<22>#<23>#r-c<01><00>t<00><00>)zAClose the DBAPI connection managed by this connection pool entry.rIrYs r.rCzConnectionPoolEntry.closerr<>r-Nr<4E>r<>)r&r'r(r)r*r<>r<>rCr,r-r.rbrbUs%<00><00><08>(<13>I<EFBFBD> <0A>$<24><0E>$<24>
2025-02-23 09:07:52 +08:00
$r-rbc<01><><00>eZdZUdZdZded<ded<ded<d ed
<d$d%d <0B>Zd ed <ed&d<0E><04>Zee jdd<10>d'd<11><04><00>Z dZ d ed<e jd(d<14><04>Ze jd)d<15><04>Zed*d<16><04>Z d$ d+d<17>Zd$d,d<18>Zed-d<19><04>Zed.d<1A><04>Zd/d<1B>Z d0 d1d<1E>Zd2d<1F>Zd-d <20>Zdd!<21>d3d"<22>Zd/d#<23>Zy)4r<34>aMaintains a position in a connection pool which references a pooled
connection.
This is an internal object used by the :class:`_pool.Pool` implementation
to provide context management to a DBAPI connection maintained by
that :class:`_pool.Pool`. The public facing interface for this class
is described by the :class:`.ConnectionPoolEntry` class. See that
class for public API details.
.. seealso::
:class:`.ConnectionPoolEntry`
:class:`.PoolProxiedConnection`
2025-08-29 00:34:40 +08:00
)<08>__pool<6F> fairy_ref<65>finalize_callback<63>freshr<68>r=<00> __weakref__<5F>__dict__z(Deque[Callable[[DBAPIConnection], None]]r<>r%r<><00>'Optional[weakref.ref[_ConnectionFairy]]r<>rnr<>c<01><><00>d|_d|_d|_d|_||_|r|j <00>t <00>|_y)NFr)r<>r<>r<>r=<00>_ConnectionRecord__pool<6F>_ConnectionRecord__connectrr<>)r<<00>poolr<6C>s r.r<>z_ConnectionRecord.__init__<5F>s=<00><00><1A><04>
<EFBFBD><1D><04><0E><1A><04><0E> $<24><04><1D><1A><04> <0B> <12> <10>N<EFBFBD>N<EFBFBD> <1C>!&<26><17><04>r-r<>r=c<01>z<00>|j<00>y|jjj|j<00>Sr:)r=r<>rjrNrYs r.r<>z#_ConnectionRecord.driver_connection<6F>s7<00><00> <0F> <20> <20> (<28><17><17>;<3B>;<3B>'<27>'<27>=<3D>=<3D><14>%<25>%<25><0E> r-<00>2.0zXThe _ConnectionRecord.connection attribute is deprecated; please use 'driver_connection'c<01><00>|jSr:<00>r=rYs r.rMz_ConnectionRecord.connection<6F><00><00><00><14>$<24>$<24>$r-r<00>_soft_invalidate_timec<01><00>iSr:r,rYs r.r<>z_ConnectionRecord.info<66><00><00><00><11> r-c<01><00>iSr:r,rYs r.r<>z_ConnectionRecord.record_info<66>rr-c<01><00><01><06><07>trtt<00>j<00><00><00>n<10>j<00><00> <00>j <00>}<02>j<00><00>t<00>|<02><07><06>}tj|<04><06><01>fd<03><08>x<01>_ }<05>t|<<00>r<1C>jj!d|<02>|S#t
$rB}t j<00>5<00>j|d<01><02>ddd<00><00>#1swY<00>xYwd}~wwxYw)NF<4E><01>_fairy_was_createdc<01>6<00><03>t<00>td<00><03>|<00>d<01><02>SdS)NF<4E>r")<01>_finalize_fairy)<04>refrgr<>ras <20><><EFBFBD>r.r<>z,_ConnectionRecord.checkout.<locals>.<lambda><3E>s1<00><><00>#<23>.<2E> <20><18>#<23>t<EFBFBD>S<EFBFBD>$<24>e<EFBFBD><12><1A><1A> r-z#Connection %r checked out from pool)rrr<>r<><00>get_connectionr<6E>r<00> safe_reraise<73>_checkin_failed<65>_should_log_debugr<67><00>weakrefr r<><00>_strong_ref_connection_recordsr<73>r<>)<08>clsr<73>r=<00>err<72>fairyr rgras ` @@r.<00>checkoutz_ConnectionRecord.checkout<75>s<><00><><00> <18><16>(<28>$<24>,<2C>,<2C>.<2E>9<>C<EFBFBD><16>,<2C>,<2C>.<2E>C<EFBFBD> <12>"<22>1<>1<>3<> <1C><14>%<25>%<25>'<27><04> <20><14>'7<><13>d<EFBFBD>C<><05>%<25>k<EFBFBD>k<EFBFBD> <11> <0E> 
2025-02-23 09:07:52 +08:00
<EFBFBD>
2025-08-29 00:34:40 +08:00
<EFBFBD><03> <0A><03>/2<>&<26>s<EFBFBD>+<2B> <0F> <10>K<EFBFBD>K<EFBFBD> <1D> <1D>5<>7G<37> <0E><15> <0C><>3<1D> <12><15>"<22>"<22>$<24><13>#<23>#<23>C<EFBFBD>E<EFBFBD>#<23>B<>%<25> <12> %<25> <12><>  <12>s/<00>B3<00>3 C><03><C9<03>C-<05>$ C9<03>-C6 <09>2C9<03>9C>c<01>L<00>|j|<01><01>|j|<02><02>y)N<>r<>r)r<><00>checkin)r<rrs r.rz!_ConnectionRecord._checkin_failed<65>s&<00><00> <0A><0F><0F>#<23><0F><1E> <0C> <0C> <0C>1<> <15>
2025-02-23 09:07:52 +08:00
r-c<01><><00>|j<00>|rtjd|z<00>yd|_|j}|j}|j
r1|j
j <00>}|<02>||<02>|j
r<01>1|jjr|jj||<00>|j|<00>y)NzDouble checkin attempted on %s)
2025-08-29 00:34:40 +08:00
r<EFBFBD>r<00>warnr=r<>r<><00>poprerr<>)r<rrMr<><00> finalizers r.rz_ConnectionRecord.checkin<69>s<><00><00> <0F>><3E>><3E> !<21>&8<> <11>I<EFBFBD>I<EFBFBD>6<><14>=<3D> ><3E> <12><1D><04><0E><19>*<2A>*<2A>
<EFBFBD><13>{<7B>{<7B><04><12>$<24>$<24><1C>.<2E>.<2E>2<>2<>4<>I<EFBFBD><19>%<25><19>*<2A>%<25><13>$<24>$<24> <10>=<3D>=<3D> <20> <20> <10>M<EFBFBD>M<EFBFBD> !<21> !<21>*<2A>d<EFBFBD> 3<> <0C><19><19>$<24>r-c<01><00>|jduSr:)r<>rYs r.r<>z_ConnectionRecord.in_uses<00><00><13>~<7E>~<7E>T<EFBFBD>)<29>)r-c<01><00>|jSr:)r<>rYs r.<00>last_connect_timez#_ConnectionRecord.last_connect_time s <00><00><13>~<7E>~<7E>r-c<01>><00>|j<00>|j<00>yyr:)r=<00>_ConnectionRecord__closerYs r.rCz_ConnectionRecord.close s<00><00> <0F> <20> <20> ,<2C> <10>L<EFBFBD>L<EFBFBD>N<EFBFBD> -r-NFc<01>X<00>|j<00>y|r2|jjj|j||<01>n1|jjj |j||<01>|<01>L|jj
2025-02-23 09:07:52 +08:00
j d|rdnd|j|jj|<01>n5|jj
j d|rdnd|j<00>|rtj<00>|_
2025-08-29 00:34:40 +08:00
y|jd<05><06>d|_y)Nz*%sInvalidate connection %r (reason: %s:%s)zSoft <20>z%sInvalidate connection %rTr<54>) r=r<>re<00>soft_invalidater<65>r<>r<><00> __class__r&r<>rr"r<>s r.r<>z_ConnectionRecord.invalidates<><00><00> <10> <20> <20> (<28> <12> <0F> <10>K<EFBFBD>K<EFBFBD> <20> <20> 0<> 0<><14>%<25>%<25>t<EFBFBD>Q<EFBFBD> <0E> <11>K<EFBFBD>K<EFBFBD> <20> <20> +<2B> +<2B>D<EFBFBD>,A<>,A<>4<EFBFBD><11> K<> <0C>=<3D> <10>K<EFBFBD>K<EFBFBD> <1E> <1E> #<23> #<23><<3C><1F><07>R<EFBFBD><14>%<25>%<25><11> <0B> <0B>$<24>$<24><11>  <0E> <11>K<EFBFBD>K<EFBFBD> <1E> <1E> #<23> #<23>,<2C><1F><07>R<EFBFBD><14>%<25>%<25> <0E> <10>)-<2D><19><19><1B>D<EFBFBD> &<26> <10>L<EFBFBD>L<EFBFBD>4<EFBFBD>L<EFBFBD> (<28>$(<28>D<EFBFBD> !r-c<01>p<00>d}|j<00>,|jj<00>|j<00><00>n%|jj
2025-02-23 09:07:52 +08:00
dkDrkt j <00>|jz
|jj
2025-08-29 00:34:40 +08:00
kDr3|jjjd|j<00>d}n<>|jj|jkDr3|jjjd|j<00>d}nK|j|jkDr2|jjjd|j<00>d}|r<|jd<04><07>|jj<00>|j<00>|j<00>J<00>|jS)NFr<46>z)Connection %r exceeded timeout; recyclingTz=Connection %r invalidated due to pool invalidation; recyclingzCConnection %r invalidated due to local soft invalidation; recyclingr<67>) r=r<><00>clearr<72>r<>rxr<>r<>r<>rorr")r<rs r.r z _ConnectionRecord.get_connection2sT<00><00><17><07> <10> <20> <20> (<28> <10>I<EFBFBD>I<EFBFBD>O<EFBFBD>O<EFBFBD> <1D> <10>N<EFBFBD>N<EFBFBD> <1C> <10>K<EFBFBD>K<EFBFBD> <20> <20>2<EFBFBD> %<25><14> <09> <09> <0B>d<EFBFBD>n<EFBFBD>n<EFBFBD>,<2C>t<EFBFBD>{<7B>{<7B>/C<>/C<>C<> <10>K<EFBFBD>K<EFBFBD> <1E> <1E> #<23> #<23>;<3B><14>%<25>%<25> <0E><1B>G<EFBFBD> <11>[<5B>[<5B> )<29> )<29>D<EFBFBD>N<EFBFBD>N<EFBFBD> :<3A> <10>K<EFBFBD>K<EFBFBD> <1E> <1E> #<23> #<23><1E><14>%<25>%<25> <0E>
2025-02-23 09:07:52 +08:00
<1B>G<EFBFBD> <11> '<27> '<27>$<24>.<2E>.<2E> 8<> <10>K<EFBFBD>K<EFBFBD> <1E> <1E> #<23> #<23><1E><14>%<25>%<25> <0E>
2025-08-29 00:34:40 +08:00
<1B>G<EFBFBD> <12> <10>L<EFBFBD>L<EFBFBD>4<EFBFBD>L<EFBFBD> (<28> <10>I<EFBFBD>I<EFBFBD>O<EFBFBD>O<EFBFBD> <1D> <10>N<EFBFBD>N<EFBFBD> <1C><13>$<24>$<24>0<>0<>0<><13>$<24>$<24>$r-c<01><><00>|jduxs>|jj|jkDxs|j|jkDSr:)r=r<>ror<>rrYs r.<00>_is_hard_or_soft_invalidatedz._ConnectionRecord._is_hard_or_soft_invalidatedfsG<00><00> <10> !<21> !<21>T<EFBFBD> )<29> =<3D><13>{<7B>{<7B>+<2B>+<2B>d<EFBFBD>n<EFBFBD>n<EFBFBD><<3C> =<3D><14>*<2A>*<2A>T<EFBFBD>^<5E>^<5E>;<3B>
2025-02-23 09:07:52 +08:00
r-r<>c<01>P<00>|jj<00>|jjjr0|jjj |j
|<00>|j
<00>J<00>|jj |j
2025-08-29 00:34:40 +08:00
|<01><01>d|_y)Nr<4E>)r<>r(r<>rerCr=r<>)r<r<>s r.<00>__closez_ConnectionRecord.__closems<><00><00> <0C><1E><1E>$<24>$<24>&<26> <0F>;<3B>;<3B> <1F> <1F> %<25> %<25> <10>K<EFBFBD>K<EFBFBD> <20> <20> &<26> &<26>t<EFBFBD>'<<3C>'<<3C>d<EFBFBD> C<><13>$<24>$<24>0<>0<>0<> <0C> <0B> <0B>%<25>%<25> <10> !<21> !<21>Y<EFBFBD> &<26>
2025-02-23 09:07:52 +08:00
<EFBFBD>!%<25><04>r-c<01><><00>|j}d|_ tj<00>|_|j |<00>x|_}|j
j d|<02>d|_|jjrI|jjj|j<00>j|j|<00>|jjj|j<00>j|j|<00>y#t$rU}tj <00>5|j
2025-08-29 00:34:40 +08:00
j d|<03>ddd<00>n#1swYnxYwYd}~yYd}~yd}~wwxYw)NzCreated new connection %rTzError on connect(): %s)r<>r=r<>r<>rmr<>r<>r<>re<00> first_connect<63>
for_modify<EFBFBD>exec_once_unless_exceptionr<6E><00>_exec_w_sync_on_first_runr<6E>rr)r<r<>rMr<>s r.<00> __connectz_ConnectionRecord.__connectws<00><00><13>{<7B>{<7B><04>!%<25><04><1D> E<01>!<21>Y<EFBFBD>Y<EFBFBD>[<5B>D<EFBFBD>N<EFBFBD>15<31>1E<31>1E<31>d<EFBFBD>1K<31> K<>D<EFBFBD> !<21>J<EFBFBD> <10>K<EFBFBD>K<EFBFBD> <1D> <1D>9<>:<3A> F<><1D>D<EFBFBD>J<EFBFBD><14>}<7D>}<7D>*<2A>*<2A><14> <0A> <0A>+<2B>+<2B>6<>6<><18>M<EFBFBD>M<EFBFBD><12>,<2C>,<2C>T<EFBFBD>-B<>-B<>D<EFBFBD>I<> <11>M<EFBFBD>M<EFBFBD> !<21> !<21> ,<2C> ,<2C><14> <0A> <0A> <0E>'<27>'<27><04>(=<3D>(=<3D>t<EFBFBD>D<><44><1D> ?<3F><15>"<22>"<22>$<24><14> <0B> <0B>!<21>!<21>":<3A>A<EFBFBD>><3E>%<25>$<24>$<24><>$<24>$<24><> ?<3F>s0<00>AD<00> E0<03>E+<03>/E<05> E+<03>E <09>E+<03>+E0)T)r<>rdr<>r%<00>rPr<>)rPr<>r<>r<>)r<>rdrPr<>)rr<>rr%rPrQ)rr%rPrQr<>)rPrnr<>r<>r<>r[)r<>r%rPrQ)r&r'r(r)r*r+r<>r<>r<>r<00>
deprecatedrMrr<>r<>r<><00> classmethodrrrr<>r rCr<>r r*r"r<>r,r-r.r<>r<>ws^<00><00><08>" <06>I<EFBFBD>@<01>?<3F> <0F>K<EFBFBD>6<>6<><14><14> )<29>0<>/<2F> <0A><0E><0E><0E><0E><14>T<EFBFBD>_<EFBFBD>_<EFBFBD> <0A> )<29><06>
2025-02-23 09:07:52 +08:00
%<25> <06><0E> %<25>$%<25><19>5<EFBFBD>$<24> <09><1E><1E><12><1F><12>
<EFBFBD><1E><1E><12><1F><12><11>!<15><11>!<15>H>B<01>
<EFBFBD> <20>
<EFBFBD>6:<3A>
<EFBFBD> <0A>
<EFBFBD> <20>.<0E>*<2A><0E>*<2A><0E><1E><0E><1E><1B>
?D<01>)<29>(<28>)<29>7;<3B>)<29> <0A>)<29>B2%<25>h
<EFBFBD>,1<>%<25>Er-r<>c<01><><00>|du}|r>|<03>J<00>tj|d<01>|<01>J<00>|j|ury|<00>J<00>|j}n+|r)tjt j
|<06>d<01>|j j}|ri|duxs|} | }
|j j xs|j j} |j jxr|j j} n
|du} dx}
} d} |<00><>|r|r|jjd|<00> |s|<01>J<00>t||||<04>}|j|usJ<00>|j||| |
<EFBFBD><05>| r_|r||_ |j<00>| rD|jj r|jj!|<00>|j#|| <0C><06>| rB|r@|r>d
|<00>d | sd nd <0A>d<0E>}|jj'|<0E>t/j0|<0E> |r|j<00>|j3<00>|<06>d|_d|_~~~y#t$$rL} |jj'dd<02><08>|r|j)| <0A> <09>t+| t,<00>s<01>Yd} ~ <0A><>d} ~ wwxYw#| rD|rA|r>d
|<00>d | sd nd <0A>d<0E>}|jj'|<0E>t/j0|<0E>wwwwxYw)acCleanup for a :class:`._ConnectionFairy` whether or not it's already
been garbage collected.
When using an async dialect no IO can happen here (without using
a dedicated thread), since this is called outside the greenlet
context and with an already running loop. In this case function
will only log a message and raise a warning.
2025-08-29 00:34:40 +08:00
NTFz$Connection %r being returned to poolr!r<>z!Exception during reset or similarr<72>rzFThe garbage collector is trying to clean up non-checked-in connection z, which will be z*dropped, as it cannot be safely terminated<65>
terminatedz<EFBFBD>. Please ensure that SQLAlchemy pooled connections are returned to the pool explicitly, either by calling ``close()`` or by using appropriate context managers to manage their lifecycle.)rrr<>r=rr rjrRrSr<>r<>r<><00>_reset<65>_pool<6F>detachre<00>close_detachedr<64>r<>r<>r<>r<>r<>rrrr<>)r=r<>r<>r rgr"r<00> is_gc_cleanup<75>dont_restore_gcedr:<00>can_manipulate_connection<6F>!can_close_or_terminate_connection<6F>requires_terminate_for_closer<65><00>messages r.r r <00>s;<00><00>(<18>t<EFBFBD>O<EFBFBD>M<EFBFBD><14><12><EFBFBD><1E><EFBFBD>&<26>*<2A>*<2A>3<EFBFBD><04>5<> <20>,<2C>,<2C>,<2C> <1C> &<26> &<26>c<EFBFBD> 1<> <12><1F>'<27>'<27>'<27>,<2C>=<3D>=<3D><18> <0E>&<26>*<2A>*<2A>7<EFBFBD>;<3B>;<3B>u<EFBFBD>+=<3D>t<EFBFBD>D<><1D> <0A> <0A>.<2E>.<2E><15><18>"<22>d<EFBFBD>*<2A>;<3B>m<EFBFBD><06>(5<>$5<>!<21><14> <0A> <0A>&<26>&<26> &<26> E<>$<24>-<2D>-<2D>*E<>*E<> *<2A> <11>M<EFBFBD>M<EFBFBD> "<22> "<22> B<>t<EFBFBD>}<7D>}<7D>'B<>'B<> %<25>
#<23>d<EFBFBD>*<2A><06>HL<48>L<>!<21>$E<>',<2C>$<24><17>#<23> <1C><14> <10>K<EFBFBD>K<EFBFBD> <1D> <1D>6<>8H<38> <0E>9 #<23><18>(<28>4<>4<>4<>(<28><18>$<24>%<25><18> <12><05> <19>)<29>)<29>-=<3D>=<3D> =<3D>=<3D> <11>L<EFBFBD>L<EFBFBD><14>&;<3B>%<25>6<> <19> <0E><16>$<24>"&<26>E<EFBFBD>K<EFBFBD><19>L<EFBFBD>L<EFBFBD>N<EFBFBD>4<><1B>}<7D>}<7D>3<>3<><1C> <0A> <0A>4<>4<>5E<35>F<><18>*<2A>*<2A>(<28>"><3E>+<2B><16><16>-<2D>,=<3D>1<>1A<31>0D<30>E'<27> A<01>E<01>)<29>'<16>'<27> '<27><18><15> <0B> <0B>!<21>!<21>'<27>*<2A><14> <09> <09>'<27>"<22><18>.<2E>8<>8<>D<><19>!<21>!<21>#<23>  <0A><18>!%<25><05><1E>#'<27><05> <20><18><19> <0A><>O<1D> <16> <10>K<EFBFBD>K<EFBFBD> <1D> <1D>3<>d<EFBFBD> <1E> <0E>!<21>!<21>,<2C>,<2C>q<EFBFBD>,<2C>1<><1D>a<EFBFBD><19>+<2B><15>,<2C><>  <16><><16>-<2D>,=<3D>1<>1A<31>0D<30>E'<27> A<01>E<01>)<29>'<16>'<27> '<27><18><15> <0B> <0B>!<21>!<21>'<27>*<2A><14> <09> <09>'<27>"<22>!-><3E>-<2D>v<EFBFBD>s-<00>BH.<00>. J<03>7AI><03>9J<00>>J<03>J<00>AKz6Dict[weakref.ref[_ConnectionFairy], _ConnectionRecord]rc<01><><00>eZdZdZdZej rd d<03>Zd d<04>Zd d<05>Z dd<06>Z
e dd<07><04>Z e dd<08><04>Z d d <09>Zd d
<EFBFBD>Zy )rOaA connection-like adapter for a :pep:`249` DBAPI connection, which
2025-02-23 09:07:52 +08:00
includes additional methods specific to the :class:`.Pool` implementation.
:class:`.PoolProxiedConnection` is the public-facing interface for the
internal :class:`._ConnectionFairy` implementation object; users familiar
with :class:`._ConnectionFairy` can consider this object to be equivalent.
.. versionadded:: 2.0 :class:`.PoolProxiedConnection` provides the public-
facing interface for the :class:`._ConnectionFairy` internal class.
2025-08-29 00:34:40 +08:00
r,c<01><00>yr:r,rYs r.r5zPoolProxiedConnection.commit2s<00><00>#r-c<01><00>yr:r,<00>r<<00>args<67>kwargss r.<00>cursorzPoolProxiedConnection.cursor4s<00><00>Cr-c<01><00>yr:r,rYs r.r6zPoolProxiedConnection.rollback6s<00><00>Cr-c<01><00>yr:r,<00>r<<00>keys r.<00> __getattr__z!PoolProxiedConnection.__getattr__8s<00><00>r-c<01><00>t<00><00>)zgReturn True if this :class:`.PoolProxiedConnection` still refers
to an active DBAPI connection.rIrYs r.r<>zPoolProxiedConnection.is_valid:<00> <00><00>
2025-02-23 09:07:52 +08:00
"<22>#<23>#r-c<01><00>t<00><00>)zVReturn True if this :class:`.PoolProxiedConnection` is detached
2025-08-29 00:34:40 +08:00
from its pool.rIrYs r.<00> is_detachedz!PoolProxiedConnection.is_detachedArOr-c<01><00>t<00><00>)aSeparate this connection from its Pool.
2025-02-23 09:07:52 +08:00
This means that the connection will no longer be returned to the
pool when closed, and will instead be literally closed. The
associated :class:`.ConnectionPoolEntry` is de-associated from this
DBAPI connection.
Note that any overall connection limiting constraints imposed by a
Pool implementation may be violated after a detach, as the detached
connection is removed from the pool's knowledge and control.
2025-08-29 00:34:40 +08:00
rIrYs r.r:zPoolProxiedConnection.detachHs <00><00>"<22>#<23>#r-c<01><00>t<00><00>)a$Release this connection back to the pool.
2025-02-23 09:07:52 +08:00
The :meth:`.PoolProxiedConnection.close` method shadows the
:pep:`249` ``.close()`` method, altering its behavior to instead
:term:`release` the proxied connection back to the connection pool.
Upon release to the pool, whether the connection stays "opened" and
pooled in the Python process, versus actually closed out and removed
from the Python process, is based on the pool implementation in use and
its configuration and current state.
2025-08-29 00:34:40 +08:00
rIrYs r.rCzPoolProxiedConnection.closeXr<>r-Nr<4E><00>rFrrGrrPr<00>rLr<>rPrr<>)r&r'r(r)r*<00>typingrr5rHr6rMr<>r<>rQr:rCr,r-r.rOrO!sS<00><00>
<08><13>I<EFBFBD> <0A><1B><1B>%<25>G<>'<27>3<> <0A>$<24><0E>$<24> <0E>$<24><0E>$<24> $<24> $r-rOc<01><><00>eZdZUdZdZded<ded< dd<07>Zedd<08><04>Zedd <09><04>Z edd
2025-02-23 09:07:52 +08:00
<EFBFBD><04>Z
d dd <0C>Z e jdd <0A><04>Zdd<0E>Zdd<0F>Zy )<19>_AdhocProxiedConnectionadprovides the :class:`.PoolProxiedConnection` interface for cases where
the DBAPI connection is not actually proxied.
This is used by the engine internals to pass a consistent
:class:`.PoolProxiedConnection` object to consuming dialects in response to
pool events that may not always have the :class:`._ConnectionFairy`
available.
2025-08-29 00:34:40 +08:00
<20>r=r<><00> _is_validrr=rbr<>c<01>.<00>||_||_d|_yr<>rY)r<r=r<>s r.r<>z _AdhocProxiedConnection.__init__xs<00><00>
!1<><04><1D>"3<><04><1F><1D><04>r-c<01>.<00>|jjSr:<00>r<>r<>rYs r.r<>z)_AdhocProxiedConnection.driver_connection<6F>s<00><00><13>&<26>&<26>8<>8<>8r-c<01><00>|jSr:rrYs r.rMz"_AdhocProxiedConnection.connection<6F>s<00><00><13>$<24>$<24>$r-c<01><00>|jS)z<>Implement is_valid state attribute.
2025-02-23 09:07:52 +08:00
for the adhoc proxied connection it's assumed the connection is valid
as there is no "invalidate" routine.
2025-08-29 00:34:40 +08:00
<20>rZrYs r.r<>z _AdhocProxiedConnection.is_valid<69>s<00><00><14>~<7E>~<7E>r-Nc<01><00>d|_yr<>r`r<>s r.r<>z"_AdhocProxiedConnection.invalidate<74>s <00><00><1F><04>r-c<01>.<00>|jjSr:<00>r<>r<>rYs r.r<>z#_AdhocProxiedConnection.record_info<66>s<00><00><13>&<26>&<26>2<>2<>2r-c<01>:<00>|jj|i|<02><01>Sr:<00>r=rHrEs r.rHz_AdhocProxiedConnection.cursor<6F>s <00><00>+<2B>t<EFBFBD>$<24>$<24>+<2B>+<2B>T<EFBFBD><<3C>V<EFBFBD><<3C><r-c<01>.<00>t|j|<01>Sr:<00>r<>r=rKs r.rMz#_AdhocProxiedConnection.__getattr__<5F><00><00><00><16>t<EFBFBD>,<2C>,<2C>c<EFBFBD>2<>2r-)r=rr<>rb)rPrr[r<>r<>r<>r<>rT)rLrrPr)r&r'r(r)r*r+r<>r<>r<>rMr<>r<>r<00>ro_non_memoized_propertyr<79>rHrMr,r-r.rXrXhs<><00><00><08>H<01>I<EFBFBD>%<25>%<25>+<2B>+<2B><1E>)<29><1E>/<2F><1E><0E>9<><0E>9<><0E>%<25><0E>%<25><0E><1E><0E><1E>?D<01><1F>(<28><1F>7;<3B><1F> <0A><1F>
2025-02-23 09:07:52 +08:00

2025-08-29 00:34:40 +08:00
<EFBFBD>"<22>"<22>3<>#<23>3<>=<3D>3r-rXc<01><><00>eZdZUdZdZded<ded<ded< d!d <09>Zd
2025-02-23 09:07:52 +08:00
ed <ed"d <0C><04>Zee jd d<0E>d#d<0F><04><00>Z e d$ d%d<11><05>Z d&d<12>Zd'd(d<13>Zd)d<14>Z d*d<15>Zed+d<16><04>Zed,d<17><04>Zed,d<18><04>Ze j*d-d<19><04>Ze j.d.d<1A><04>Z d/ d0d<1B>Zd1d<1C>Zd2d<1D>Zd)d<1E>Zd)d<1F>Zd'd3d <20>Zy)4r<34>a&Proxies a DBAPI connection and provides return-on-dereference
support.
This is an internal object used by the :class:`_pool.Pool` implementation
to provide context management to a DBAPI connection delivered by
that :class:`_pool.Pool`. The public facing interface for this class
is described by the :class:`.PoolProxiedConnection` class. See that
class for public API details.
The name "fairy" is inspired by the fact that the
:class:`._ConnectionFairy` object's lifespan is transitory, as it lasts
only for the length of a specific DBAPI connection being checked out from
the pool, and additionally that as a transparent proxy, it is mostly
invisible.
.. seealso::
:class:`.PoolProxiedConnection`
:class:`.ConnectionPoolEntry`
2025-08-29 00:34:40 +08:00
)r=r<><00>_echor9<00>_counterr<72>r<>rdr<>rr=rfrkc<01>J<00>||_d|_||_||_||_y)Nr)r9rlr=r<>rk)r<r<>r=r<>rgs r.r<>z_ConnectionFairy.__init__<5F>s)<00><00><1A><04>
2025-02-23 09:07:52 +08:00
<EFBFBD><19><04> <0A> 0<><04><1D>"3<><04><1F><19><04>
2025-08-29 00:34:40 +08:00
r-<00>Optional[_ConnectionRecord]r<>c<01>H<00>|j<00>y|jjSr:r]rYs r.r<>z"_ConnectionFairy.driver_connection<6F>s#<00><00> <0F> "<22> "<22> *<2A><17><13>&<26>&<26>8<>8<>8r-r<>zWThe _ConnectionFairy.connection attribute is deprecated; please use 'driver_connection'c<01><00>|jSr:rrYs r.rMz_ConnectionFairy.connection<6F>rr-Nc<01>~<00>|s1tj|<01>}|<02>tj|<03>|_|j
2025-02-23 09:07:52 +08:00
<00>Jd<01><00>|j <00>Jd<02><00>|xjdz c_|jjs |jr|jdk7r|Sd}|dkD<00>r:|j
j}d|j
_
|jr<>|s<>|jr&|jjd|j <00>|jj|j <00>}|sx|jr&|jjd|j <00>t!j"<00><00>|jr&|jjd |j <00>|jj|j |j
|<03>|S|jj)d<0F>|j+<00>t!j8d<10><00>#t j$$<00>r#}|j&rL|jj)d
|<07>|j
j+|<07>|j-||d<06> <0B>nB|jj)d |j |<07>|j
j+|<07> |j
j/<00>|_nY#t0$rM}t3j4<00>5|j
j7|d <0A><0E>~ddd<00><00>#1swY<00>xYwd}~wwxYw|dz}Yd}~n`d}~wt0$rQ} t3j4<00>5|j
}
|
<EFBFBD>|
2025-08-29 00:34:40 +08:00
j7| d <0A><0E>~ddd<00><00>#1swY<00>xYwd} ~ wwxYw|dkDr<02><03><13><01><>)Nz,can't 'checkout' a detached connection fairyz0can't 'checkout' an invalidated connection fairyr1rrFzPool pre-ping on connection %sz;Pool pre-ping on connection %s failed, will invalidate poolz)Connection %s is fresh, skipping pre-pingzoDisconnection detected on checkout, invalidating all pooled connections prior to current timestamp (reason: %r)<29>r<>zVDisconnection detected on checkout, invalidating individual connection %s (reason: %r)Trz+Reconnection attempts exhausted on checkoutzThis connection is closed)r<>rrr <00>currentr<74>r=rlreryr<>rkr<>r<>rjrKr<00>InvalidatePoolError<6F>DisconnectionError<6F>invalidate_poolr<6C>r<>r<>r r<>rrr<00>InvalidRequestError) rr<><00> threadconnsr<00>attempts<74>connection_is_fresh<73>resultr<74>r<00>be_outerras r.r<>z_ConnectionFairy._checkout<75>sj<00><00><15>%<25>.<2E>.<2E>t<EFBFBD>4<>E<EFBFBD><1A>&<26>&-<2D>k<EFBFBD>k<EFBFBD>%<25>&8<> <0B>#<23> <12> $<24> $<24> 0<> :<3A> 9<> :<3A> 0<> <12> "<22> "<22> .<2E> ><3E> =<3D> ><3E> .<2E> <0E><0E><0E>!<21><1B><0E><14> <0A> <0A>&<26>&<26>t<EFBFBD>~<7E>~<7E> <12>^<5E>^<5E>q<EFBFBD> <20><18>L<EFBFBD><15><08><16><11>l<EFBFBD>"'<27>":<3A>":<3A>"@<40>"@<40> <1F>-2<>E<EFBFBD> $<24> $<24> *<2A>S <16><17>><3E>><3E>.<2E> <20>;<3B>;<3B> <20>K<EFBFBD>K<EFBFBD>-<2D>-<2D> @<40> %<25> 6<> 6<><1E>"&<26><1D><1D>!?<3F>!?<3F>!<21>2<>2<>"<1A><06> &<26>$<24>{<7B>{<7B> $<24> <0B> <0B> 1<> 1<>%;<3B>$)<29>$:<3A>$:<3A>!"<22>
2025-02-23 09:07:52 +08:00
#&<26>"9<>"9<>";<3B>;<3B><1E><1B><1B><1C> <0B> <0B>)<29>)<29>G<>!<21>2<>2<><1A>
2025-08-29 00:34:40 +08:00
<15> <0A> <0A>&<26>&<26><19>*<2A>*<2A>E<EFBFBD>,D<>,D<>e<EFBFBD><12><1D> <0C>r <0A> <0B> <0B><18><18>F<>G<> <0A><18><18><1A><11>%<25>%<25>&A<>B<>B<><42>u<17>)<29>)<29>' <1E><14>$<24>$<24><18>K<EFBFBD>K<EFBFBD>$<24>$<24>9<><1A> <16> <1A>,<2C>,<2C>7<>7<><01>:<3A><18>$<24>$<24>U<EFBFBD>A<EFBFBD><05>$<24>><3E><18>K<EFBFBD>K<EFBFBD>$<24>$<24>M<01><1D>.<2E>.<2E><19> <16> <1A>,<2C>,<2C>7<>7<><01>:<3A><1A><1D>0<>0<>?<3F>?<3F>A<><1A>*<2A><>%<25><1A><1D>*<2A>*<2A>,<2C><1D>0<>0<>@<40>@<40><1F>/3<>A<01><1A>"<22>-<2D><1A>-<2D><1A><><1A><>"<19>A<EFBFBD> <0A><08><> <20> <16><19>&<26>&<26>(<28><1F>2<>2<>C<EFBFBD><1A><EFBFBD><1B>+<2B>+<2B>$<24>/3<>,<2C><1A><1E>)<29><16>)<29><16><> <16><>Q<17><11>l<EFBFBD>sz<00>DH$<00>$N3<03>8BM<03>K3<02>2M<03>3 M <05><M<05>L8<07>/ M<05>8M <0B>=M<05>M <05> M<03> N3<03>"N.<03>6#N"<05> N.<03>"N+ <09>'N.<03>.N3c<01>D<00>tj|j|<00><01>S)N)r)r<>r<>r9rYs r.<00>_checkout_existingz#_ConnectionFairy._checkout_existingfs<00><00><1F>)<29>)<29>$<24>*<2A>*<2A>D<EFBFBD>)<29>A<>Ar-c <01>x<00>t|j|j|jd|j||<00><01>y)N)r"r)r r=r<>r9rk)r<r"s r.r<>z_ConnectionFairy._checkinis3<00><00><17> <10> !<21> !<21> <10> #<23> #<23> <10>J<EFBFBD>J<EFBFBD> <10> <10>J<EFBFBD>J<EFBFBD>"7<><16>
r-c<01>$<00>|j<00>yr:rrrYs r.<00>_closez_ConnectionFairy._closets <00><00> <0C> <0A> <0A>r-c <01><><00>|jjr=|jj|j|jt |||<04><01><00>|sy|j
2025-02-23 09:07:52 +08:00
t ur<>|r3|jru|jjd|j<00>y|jr&|jjd|j<00>|jj|<00>yy|j
2025-08-29 00:34:40 +08:00
turN|jr&|jjd|j<00>|jj|<00>yy)Nr!z.Connection %s reset, transaction already resetz Connection %s rollback-on-returnzConnection %s commit-on-return)re<00>resetr=r<>r r{r2rkr<>r<>rjr>r3r@)r<r<>r"r#r$s r.r8z_ConnectionFairy._resetws<00><00> <10>=<3D>=<3D> <1E> <1E> <10>M<EFBFBD>M<EFBFBD> <1F> <1F><14>%<25>%<25><14>'<27>'<27><1E>*?<3F>#1<>!-<2D><12> <0E><1C> <12> <0F> <20> <20>N<EFBFBD> 2<>$<24><17>:<3A>:<3A><18>K<EFBFBD>K<EFBFBD>%<25>%<25>H<><1C>-<2D>-<2D><16>
<18>:<3A>:<3A><18>K<EFBFBD>K<EFBFBD>%<25>%<25>:<3A><1C>-<2D>-<2D><16><15> <0A> <0A>)<29>)<29>$<24>/<2F><1E><12> "<22> "<22>l<EFBFBD> 2<><13>z<EFBFBD>z<EFBFBD><14> <0B> <0B>!<21>!<21>4<><18>)<29>)<29><12> <11>M<EFBFBD>M<EFBFBD> #<23> #<23>D<EFBFBD> )<29> 3r-c<01>.<00>|jjSr:)r9r<>rYs r.<00>_loggerz_ConnectionFairy._logger<65>s<00><00><13>z<EFBFBD>z<EFBFBD> <20> <20> r-c<01><00>|jduSr:rrYs r.r<>z_ConnectionFairy.is_valid<69>s<00><00><13>$<24>$<24>D<EFBFBD>0<>0r-c<01><00>|jduSr:)r<>rYs r.rQz_ConnectionFairy.is_detached<65>s<00><00><13>&<26>&<26>$<24>.<2E>.r-c<01>J<00>|j<00>iS|jjSr:)r<>r<>rYs r.r<>z_ConnectionFairy.info<66>s%<00><00> <0F> "<22> "<22> *<2A><15>I<EFBFBD><17>*<2A>*<2A>/<2F>/<2F> /r-c<01>H<00>|j<00>y|jjSr:rcrYs r.r<>z_ConnectionFairy.record_info<66>s#<00><00> <0F> "<22> "<22> *<2A><17><17>*<2A>*<2A>6<>6<> 6r-c<01><><00>|j<00>tjd<01>y|jr|jj ||<02><02>|sd|_|j <00>yy)Nz.Can't invalidate an already-closed connection.)r<>r<>)r=rrr<>r<>r<>r<>s r.r<>z_ConnectionFairy.invalidate<74>s_<00><00> <10> <20> <20> (<28> <10>I<EFBFBD>I<EFBFBD>F<> G<> <12> <0F> "<22> "<22> <10> #<23> #<23> .<2E> .<2E><11><14> .<2E> ><3E><13>%)<29>D<EFBFBD> !<21> <11>M<EFBFBD>M<EFBFBD>O<EFBFBD> r-c<01>V<00>|j<00>J<00>|jj|i|<02><01>Sr:rerEs r.rHz_ConnectionFairy.cursor<6F>s2<00><00><13>$<24>$<24>0<>0<>0<>+<2B>t<EFBFBD>$<24>$<24>+<2B>+<2B>T<EFBFBD><<3C>V<EFBFBD><<3C><r-c<01>.<00>t|j|<01>Sr:rgrKs r.rMz_ConnectionFairy.__getattr__<5F>rhr-c<01><><00>|j<00><>|j}d|_d|_|jj |j<00>|j
j <00>|_d|_|jjjr1|jjj|j|<01>yyyr:) r<>r<>r=r9r<>r<><00>copyrer:r`s r.r:z_ConnectionFairy.detach<63>s<><00><00> <0F> "<22> "<22> .<2E><16>)<29>)<29>C<EFBFBD> <20>C<EFBFBD>M<EFBFBD>#'<27>C<EFBFBD> <20> <10>J<EFBFBD>J<EFBFBD> &<26> &<26>t<EFBFBD>'><3E>'><3E> ?<3F><1D> <09> <09><0E><0E>(<28>D<EFBFBD>I<EFBFBD>&*<2A>D<EFBFBD> #<23><13>z<EFBFBD>z<EFBFBD>"<22>"<22>)<29>)<29><14>
2025-02-23 09:07:52 +08:00
<EFBFBD>
2025-08-29 00:34:40 +08:00
<EFBFBD>#<23>#<23>*<2A>*<2A>4<EFBFBD>+@<40>+@<40>#<23>F<>*<2A> /r-c<01>n<00>|xjdzc_|jdk(r|j<00>yy)Nr1r<00>rlr<>rYs r.rCz_ConnectionFairy.close<73>s*<00><00> <0C> <0A> <0A><11><1A> <0A> <0F>=<3D>=<3D>A<EFBFBD> <1D> <10>M<EFBFBD>M<EFBFBD>O<EFBFBD> r-c<01>r<00>|xjdzc_|jdk(r|j|<01><03>yy)Nr1rr
r<>)r<<00>transaction_resets r.<00>_close_specialz_ConnectionFairy._close_special<61>s0<00><00> <0C> <0A> <0A><11><1A> <0A> <0F>=<3D>=<3D>A<EFBFBD> <1D> <10>M<EFBFBD>M<EFBFBD>0A<30>M<EFBFBD> B<> r-)r<>rdr=rr<>r<>rgrfr3r[)NN)r<>rdrxzOptional[threading.local]r<00>Optional[_ConnectionFairy]rPr<>)rPr<>)F)r"r%rPrQr<>)
r<EFBFBD>rdr"r%r#r%r$r%rPrQ)rPzlog._IdentifiedLoggerTyper<65>r<>r<>r<>r<>rTrU)r<>r%rPrQ)r&r'r(r)r*r+r<>r<>r<>rr4rMr5r<>r~r<>r<>r8r<>r<>rQr<>r<>rir<>r<>rHrMr:rCr<>r,r-r.r<>r<><00>s<><00><00><08>0<06>I<EFBFBD> <0F>J<EFBFBD>%<25>%<25> <1C><1C> <1A><12> <1A>*<2A> <1A>-<2D> <1A>
2025-02-23 09:07:52 +08:00
 <20> <1A>4<>3<> <0A>9<><0E>9<>
<0E><14>T<EFBFBD>_<EFBFBD>_<EFBFBD> <0A> )<29><06>
%<25> <06><0E> %<25><11>26<32>,0<> {C<01><12>{C<01>/<2F>{C<01>*<2A> {C<01>
<1A> {C<01><11>{C<01>zB<01> 
<EFBFBD><18>)*<2A><12>)*<2A> $<24>)*<2A><1D> )*<2A>
<1B> )*<2A>
<0E> )*<2A>V<0E>!<21><0E>!<21><0E>1<><0E>1<><0E>/<2F><0E>/<2F>
<EFBFBD><1E><1E>0<><1F>0<> 
<EFBFBD>"<22>"<22>7<>#<23>7<>?D<01><1C>(<28><1C>7;<3B><1C> <0A><1C> =<3D>3<>G<01>"<1C>
2025-08-29 00:34:40 +08:00
Cr-r<>)FN)r=r<>r<>rnr<>rdr r<>rgzOptional[log._EchoFlagType]r"r%rr<>rPrQ)?r)<00>
__future__r<00> collectionsr<00> dataclasses<65>enumr<00> threadingr<67>rVrrrr r
r r r rrrr$rrrr<00> util.typingrr<00>engine.interfacesrrrrrr<00> sql._typingr<00> dataclassr r0r<><00>listr2r3r4r8rUrWr^<00>
Identified<EFBFBD> EventTargetrdr<>rbr<>r rr+rOrXr<>r,r-r.<00><module>r<>s<><00><01>,<2C>"<22><1D><12><15><10> <0B> <0A><16><1B><17><18><17><17><1B><18> <20><18><0E><14><12><12><13>!<21>"<22><10>3<>/<2F>+<2B>'<27>'<27>"<22>'<27><17><1B><16><16>d<EFBFBD>#<23>)<08>)<08>$<24>)<08>X<13><14><13><1B><0E> <0B> 3<>4<>6<><02><12>,0<>
<EFBFBD>+;<3B>(<28><0E> <0C>j<EFBFBD> <1A> <1A>F<14> <0C><14>/<2F>X<EFBFBD>/<2F>I<01><18>I<01>{$<24>3<EFBFBD>><3E>><3E>5<EFBFBD>,<2C>,<2C>{$<24>| y$<24>y$<24>x$<24>+<2B>$<24>DZE<01>+<2B>ZE<01>J #(<28>(,<2C>A<0E>/<2F>A<0E>2<>A<0E> <0F>A<0E>
2025-02-23 09:07:52 +08:00
<06> A<0E> &<26>A<0E> <20>A<0E> &<26>A<0E>
<EFBFBD>A<0E>T<07><1F>!<02><07>
2025-08-29 00:34:40 +08:00
D$<24>-<2D>D$<24>N83<>3<>83<>vIC<01>,<2C>ICr-