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

264 lines
14 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>4<00><01><><00>ddlmZddlZddlmZddlmZddlmZddlmZddlmZdd lm Z dd
2025-02-23 09:07:52 +08:00
lm
Z
dd lm Z d d l m Z d dl mZejr d dlmZd dlmZGd<11>de j(e <00>Zy)<13>)<01> annotationsN)<01>Any)<01>Optional)<01>Type)<01>Union<6F>)<01>ConnectionPoolEntry)<01>Pool)<01>PoolProxiedConnection)<01>PoolResetState<74>)<01>event)<01>util)<01>Engine)<01>DBAPIConnectionc<01>~<00>eZdZdZdZeZejd<03>e dd<04><04><00>Z
e dd<05><04>Z dd<08>Z dd <09>Z dd
<EFBFBD>Z dd <0B>Zej"d ddgd <0A><00> dd<0E><04>Z dd<0F>Z dd<10>Z dd<11>Z dd<12>Zdd<13>Zy)<1D>
PoolEventsa<EFBFBD>Available events for :class:`_pool.Pool`.
The methods here define the name of an event as well
as the names of members that are passed to listener
functions.
e.g.::
from sqlalchemy import event
def my_on_checkout(dbapi_conn, connection_rec, connection_proxy):
"handle an on checkout event"
event.listen(Pool, "checkout", my_on_checkout)
In addition to accepting the :class:`_pool.Pool` class and
:class:`_pool.Pool` instances, :class:`_events.PoolEvents` also accepts
:class:`_engine.Engine` objects and the :class:`_engine.Engine` class as
targets, which will be resolved to the ``.pool`` attribute of the
given engine or the :class:`_pool.Pool` class::
engine = create_engine("postgresql+psycopg2://scott:tiger@localhost/test")
# will associate with engine.pool
event.listen(engine, "checkout", my_on_checkout)
<20>SomeEngineOrPoolzsqlalchemy.enginec<01>f<00>tjs$tjjj
}t |t<00>r&t|<03>rtSt|t<00>sJ<00>|St |<03>r |jSt |t<00>r|St|d<01>r|j<00>yy)N<>_no_async_engine_events) <0A>typing<6E> TYPE_CHECKINGr<00> preloaded<65>enginer<00>
isinstance<EFBFBD>type<70>
issubclassr
<00>pool<6F>hasattrr)<04>cls<6C>target<65>
2025-08-29 00:34:40 +08:00
identifierrs <20>CD:\pythonpj\aitsc\.venv\Lib\site-packages\sqlalchemy/pool/events.py<70> _accept_withzPoolEvents._accept_with=s<><00><00><16>#<23>#<23><19>^<5E>^<5E>*<2A>*<2A>1<>1<>F<EFBFBD> <15>f<EFBFBD>d<EFBFBD> #<23><19>&<26>&<26>)<29><1B> <0B>!<21>&<26>$<24>/<2F>/<2F>/<2F><1D> <0A> <17><06><06> '<27><19>;<3B>;<3B> <1E> <17><06><04> %<25><19>M<EFBFBD> <14>V<EFBFBD>6<> 7<> <12> *<2A> *<2A> ,<2C><17>c <01>x<00>|j}|jd|j<00>|jdi|<02><01>y)N<>asyncio<69>)<04>dispatch_target<65>
2025-02-23 09:07:52 +08:00
setdefault<EFBFBD> _is_asyncio<69> base_listen)r <00> event_key<65>kwr!s r#<00>_listenzPoolEvents._listenVs6<00><00> <1B>*<2A>*<2A><06>
<EFBFBD> <0A> <0A>i<EFBFBD><16>!3<>!3<>4<><1D> <09><1D><1D>#<23><02>#r%<00>dbapi_connection<6F>connection_recordc<01><00>y)aCalled at the moment a particular DBAPI connection is first
created for a given :class:`_pool.Pool`.
This event allows one to capture the point directly after which
the DBAPI module-level ``.connect()`` method has been used in order
to produce a new DBAPI connection.
:param dbapi_connection: a DBAPI connection.
The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
:param connection_record: the :class:`.ConnectionPoolEntry` managing
the DBAPI connection.
Nr(<00><03>selfr0r1s r#<00>connectzPoolEvents.connectb<00><00>r%c<01><00>y)a)Called exactly once for the first time a DBAPI connection is
checked out from a particular :class:`_pool.Pool`.
The rationale for :meth:`_events.PoolEvents.first_connect`
is to determine
information about a particular series of database connections based
on the settings used for all connections. Since a particular
:class:`_pool.Pool`
refers to a single "creator" function (which in terms
of a :class:`_engine.Engine`
refers to the URL and connection options used),
it is typically valid to make observations about a single connection
that can be safely assumed to be valid about all subsequent
connections, such as the database version, the server and client
encoding settings, collation settings, and many others.
:param dbapi_connection: a DBAPI connection.
The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
:param connection_record: the :class:`.ConnectionPoolEntry` managing
the DBAPI connection.
Nr(r3s r#<00> first_connectzPoolEvents.first_connectvr6r%c<01><00>y)a<>Called when a connection is retrieved from the Pool.
:param dbapi_connection: a DBAPI connection.
The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
:param connection_record: the :class:`.ConnectionPoolEntry` managing
the DBAPI connection.
:param connection_proxy: the :class:`.PoolProxiedConnection` object
which will proxy the public interface of the DBAPI connection for the
lifespan of the checkout.
If you raise a :class:`~sqlalchemy.exc.DisconnectionError`, the current
connection will be disposed and a fresh connection retrieved.
Processing of all checkout listeners will abort and restart
using the new connection.
.. seealso:: :meth:`_events.ConnectionEvents.engine_connect`
- a similar event
which occurs upon creation of a new :class:`_engine.Connection`.
Nr()r4r0r1<00>connection_proxys r#<00>checkoutzPoolEvents.checkout<75>r6r%c<01><00>y)a<>Called when a connection returns to the pool.
Note that the connection may be closed, and may be None if the
connection has been invalidated. ``checkin`` will not be called
for detached connections. (They do not return to the pool.)
:param dbapi_connection: a DBAPI connection.
The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
:param connection_record: the :class:`.ConnectionPoolEntry` managing
the DBAPI connection.
Nr(r3s r#<00>checkinzPoolEvents.checkin<69>r6r%z2.0c<01>
<00>||fS)Nr()r0r1<00> reset_states r#<00><lambda>zPoolEvents.<lambda><3E>s<00><00> <1C> <1D>B
r%c<01><00>y)a<>Called before the "reset" action occurs for a pooled connection.
This event represents
when the ``rollback()`` method is called on the DBAPI connection
before it is returned to the pool or discarded.
A custom "reset" strategy may be implemented using this event hook,
which may also be combined with disabling the default "reset"
behavior using the :paramref:`_pool.Pool.reset_on_return` parameter.
The primary difference between the :meth:`_events.PoolEvents.reset` and
:meth:`_events.PoolEvents.checkin` events are that
:meth:`_events.PoolEvents.reset` is called not just for pooled
connections that are being returned to the pool, but also for
connections that were detached using the
:meth:`_engine.Connection.detach` method as well as asyncio connections
that are being discarded due to garbage collection taking place on
connections before the connection was checked in.
Note that the event **is not** invoked for connections that were
invalidated using :meth:`_engine.Connection.invalidate`. These
events may be intercepted using the :meth:`.PoolEvents.soft_invalidate`
and :meth:`.PoolEvents.invalidate` event hooks, and all "connection
close" events may be intercepted using :meth:`.PoolEvents.close`.
The :meth:`_events.PoolEvents.reset` event is usually followed by the
:meth:`_events.PoolEvents.checkin` event, except in those
cases where the connection is discarded immediately after reset.
:param dbapi_connection: a DBAPI connection.
The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
:param connection_record: the :class:`.ConnectionPoolEntry` managing
the DBAPI connection.
:param reset_state: :class:`.PoolResetState` instance which provides
information about the circumstances under which the connection
is being reset.
.. versionadded:: 2.0
.. seealso::
:ref:`pool_reset_on_return`
:meth:`_events.ConnectionEvents.rollback`
:meth:`_events.ConnectionEvents.commit`
Nr()r4r0r1r?s r#<00>resetzPoolEvents.reset<65>r6r%c<01><00>y)a!Called when a DBAPI connection is to be "invalidated".
This event is called any time the
:meth:`.ConnectionPoolEntry.invalidate` method is invoked, either from
API usage or via "auto-invalidation", without the ``soft`` flag.
The event occurs before a final attempt to call ``.close()`` on the
connection occurs.
:param dbapi_connection: a DBAPI connection.
The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
:param connection_record: the :class:`.ConnectionPoolEntry` managing
the DBAPI connection.
:param exception: the exception object corresponding to the reason
for this invalidation, if any. May be ``None``.
.. seealso::
:ref:`pool_connection_invalidation`
Nr(<00>r4r0r1<00> exceptions r#<00>
invalidatezPoolEvents.invalidater6r%c<01><00>y)aNCalled when a DBAPI connection is to be "soft invalidated".
This event is called any time the
:meth:`.ConnectionPoolEntry.invalidate`
method is invoked with the ``soft`` flag.
Soft invalidation refers to when the connection record that tracks
this connection will force a reconnect after the current connection
is checked in. It does not actively close the dbapi_connection
at the point at which it is called.
:param dbapi_connection: a DBAPI connection.
The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
:param connection_record: the :class:`.ConnectionPoolEntry` managing
the DBAPI connection.
:param exception: the exception object corresponding to the reason
for this invalidation, if any. May be ``None``.
Nr(rDs r#<00>soft_invalidatezPoolEvents.soft_invalidate!r6r%c<01><00>y)a<>Called when a DBAPI connection is closed.
The event is emitted before the close occurs.
The close of a connection can fail; typically this is because
the connection is already closed. If the close operation fails,
the connection is discarded.
The :meth:`.close` event corresponds to a connection that's still
associated with the pool. To intercept close events for detached
connections use :meth:`.close_detached`.
:param dbapi_connection: a DBAPI connection.
The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
:param connection_record: the :class:`.ConnectionPoolEntry` managing
the DBAPI connection.
Nr(r3s r#<00>closezPoolEvents.close=r6r%c<01><00>y)a<>Called when a DBAPI connection is "detached" from a pool.
This event is emitted after the detach occurs. The connection
is no longer associated with the given connection record.
:param dbapi_connection: a DBAPI connection.
The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
:param connection_record: the :class:`.ConnectionPoolEntry` managing
the DBAPI connection.
Nr(r3s r#<00>detachzPoolEvents.detachVr6r%c<01><00>y)a<>Called when a detached DBAPI connection is closed.
The event is emitted before the close occurs.
The close of a connection can fail; typically this is because
the connection is already closed. If the close operation fails,
the connection is discarded.
:param dbapi_connection: a DBAPI connection.
The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
Nr()r4r0s r#<00>close_detachedzPoolEvents.close_detachedhr6r%N)r!z-Union[Pool, Type[Pool], Engine, Type[Engine]]r"<00>str<74>returnz!Optional[Union[Pool, Type[Pool]]])r-zevent._EventKey[Pool]r.rrP<00>None)r0rr1r rPrQ)r0rr1r r:r rPrQ)r0zOptional[DBAPIConnection]r1r rPrQ)r0rr1r r?r rPrQ)r0rr1r rEzOptional[BaseException]rPrQ)r0rrPrQ)<18>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__<5F>_target_class_docr
<00>_dispatch_targetr<00>preload_module<6C> classmethodr$r/r5r8r;r=r<00>_legacy_signaturerBrFrHrJrLrNr(r%r#rrs <00><00><08><+<2B><15><1B><14><18>T<EFBFBD><18><18>,<2C>-<2D><10><18>=<3D><18><18><18>
+<2B> <18><11>.<2E><18>.<11> $<24>(<28> $<24><12> $<24>
<0E> $<24><11> $<24> <0C>)<29> <0C>/<2F> <0C>
<0E>  <0C>( <0C>)<29> <0C>/<2F> <0C>
<0E>  <0C>: <0C>)<29> <0C>/<2F> <0C>0<>  <0C>
<0E>  <0C>: <0C>3<> <0C>/<2F> <0C>
<0E>  <0C>&<1D>U<EFBFBD><1C><1C> <0A> <1B>0<>1<>
<EFBFBD><06>6 <0C>)<29>6 <0C>/<2F>6 <0C>$<24> 6 <0C>
<0E> 6 <0C><06>6 <0C>p <0C>)<29> <0C>/<2F> <0C>+<2B>  <0C>
<0E>  <0C>< <0C>)<29> <0C>/<2F> <0C>+<2B>  <0C>
<0E>  <0C>8 <0C>)<29> <0C>/<2F> <0C>
<0E>  <0C>2 <0C>)<29> <0C>/<2F> <0C>
<0E>  <0C>$  r%r)<16>
__future__rrrrrr<00>baser r
r r <00>rrrrr<00>engine.interfacesr<00>Eventsrr(r%r#<00><module>r`sQ<00><01>#<23> <0A><16><1B><17><18>%<25><16>'<27> <20><14><13> <09><17><17><1F>3<>Y <0C><15><1C><1C>d<EFBFBD>#<23>Y r%