zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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
U
¸ý°dRGã@s´dZddlmZddlZddlZddlZddlmZddlmZddlmZddlm    Z    ddlm
Z
dd    lm Z dd
lm Z dd lm Z ddlZd d lmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZddlmZddlmZddlmZddlmZddlmZej r@ddl m!Z!Gdd„deƒZ"Gdd„de"ƒZ#Gd d!„d!e#ƒZ$Gd"d#„d#eƒZ%Gd$d%„d%eƒZ&Gd&d'„d'eƒZ'Gd(d)„d)eƒZ(dS)*zPool implementation classes.
 
é)Ú annotationsN)ÚAny)Úcast)ÚList)ÚOptional)ÚSet)ÚType)Ú TYPE_CHECKING)ÚUnioné)Ú_AsyncConnDialect)Ú_ConnectionFairy©Ú_ConnectionRecord)Ú_CreatorFnType)Ú_CreatorWRecFnType)ÚConnectionPoolEntry)ÚPool)ÚPoolProxiedConnectioné)Úexc)Úutil)Úchop_traceback)Úqueue)ÚLiteral)ÚDBAPIConnectionc@sðeZdZUdZdZejZded<ded<d1d
d d d d ddœdd„Z    dddœdd„Z
ddœdd„Z d dœdd„Z ddœdd„Z ddœdd „Zddœd!d"„Zd#dœd$d%„Zd dœd&d'„Zd dœd(d)„Zd dœd*d+„Zd dœd,d-„Zd dœd.d/„Zd0S)2Ú    QueuePoolzí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.
 
    Fú1Type[sqla_queue.QueueCommon[ConnectionPoolEntry]]Ú _queue_classz+sqla_queue.QueueCommon[ConnectionPoolEntry]Ú_pooléé
ç>@ú)Union[_CreatorFnType, _CreatorWRecFnType]ÚintÚfloatÚboolr)ÚcreatorÚ    pool_sizeÚ max_overflowÚtimeoutÚuse_lifoÚkwcKsPtj||f|Ž|j||d|_d||_|dkr6dn||_||_t ¡|_    dS)aÙ    
        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.
 
        )r+réÿÿÿÿN)
rÚ__init__rrÚ    _overflowÚ _max_overflowÚ_timeoutÚ    threadingÚLockÚ_overflow_lock)Úselfr'r(r)r*r+r,©r6úKd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/pool/impl.pyr.?s ?
zQueuePool.__init__rÚNone©ÚrecordÚreturnc CsFz|j |d¡Wn.tjk
r@z | ¡W5| ¡XYnXdS©NF)rÚputÚ
sqla_queueÚFullÚ _dec_overflowÚclose©r5r:r6r6r7Ú_do_return_conn…s  zQueuePool._do_return_conn©r;c CsÎ|jdk}|o|j|jk}z|j ||j¡WStjk
rBYnX|r‚|j|jkr‚|s`| ¡Stj    d| 
¡|  ¡|jfdd‚|  ¡rÂz
|  ¡WSt ¡| ¡W5QRX‚YqÊXn| ¡SdS)Nr-zSQueuePool limit of size %d overflow %d reached, connection timed out, timeout %0.2fZ3o7r)Úcode)r0r/rÚgetr1r>ÚEmptyÚ_do_getrÚ TimeoutErrorÚsizeÚoverflowÚ _inc_overflowÚ_create_connectionrZ safe_reraiser@)r5Z use_overflowÚwaitr6r6r7rHŽs.
þü
 
 
zQueuePool._do_getc    Csh|jdkr|jd7_dS|j<|j|jkrL|jd7_W5QR£dSW5QR£dSW5QRXdS)Nr-r TF©r0r/r4©r5r6r6r7rL®s
 zQueuePool._inc_overflowz Literal[True]c    CsJ|jdkr|jd8_dS|j|jd8_W5QR£dSQRXdS)Nr-r TrOrPr6r6r7r@¹s 
zQueuePool._dec_overflowcCsJ|j d¡|j|j|jj|j|j|jj|j    |j
|j |j |j |j|jd S)NúPool recreating) r(r)Úpre_pingr+r*ÚrecycleÚechoÚ logging_nameÚreset_on_returnÚ    _dispatchÚdialect)ÚloggerÚinfoÚ    __class__Ú_creatorrÚmaxsizer0Ú    _pre_pingr+r1Ú_recyclerTÚ_orig_logging_nameÚ_reset_on_returnÚdispatchÚ_dialectrPr6r6r7ÚrecreateÁs ôzQueuePool.recreatecCsZz|j d¡}| ¡Wqtjk
r2Yq6YqXqd| ¡|_|j d|     ¡¡dS)NFrzPool disposed. %s)
rrFrAr>rGrJr/rYrZÚstatus©r5Úconnr6r6r7ÚdisposeÒs   zQueuePool.disposeÚstrcCs d| ¡| ¡| ¡| ¡fS)Nz_Pool size: %d  Connections in pool: %d Current Overflow: %d Current Checked out connections: %d)rJÚ    checkedinrKÚ
checkedoutrPr6r6r7reÝsüýÿzQueuePool.statuscCs|jjS©N)rr]rPr6r6r7rJêszQueuePool.sizecCs|jSrl)r1rPr6r6r7r*íszQueuePool.timeoutcCs
|j ¡Srl)rÚqsizerPr6r6r7rjðszQueuePool.checkedincCs|jjr|jSdS)Nr)rr]r/rPr6r6r7rKószQueuePool.overflowcCs|jj|j ¡|jSrl)rr]rmr/rPr6r6r7rköszQueuePool.checkedoutN)r r!r"F)Ú__name__Ú
__module__Ú __qualname__Ú__doc__Ú _is_asyncior>ÚQueuerÚ__annotations__r.rCrHrLr@rdrhrerJr*rjrKrkr6r6r6r7r-s,
þ
úF        rc@s&eZdZUdZejZded<eƒZ    dS)ÚAsyncAdaptedQueuePoolTrrN)
rnrorprrr>ZAsyncAdaptedQueuerrtr rcr6r6r6r7ruús
þ
ruc@seZdZejZdS)ÚFallbackAsyncAdaptedQueuePoolN)rnrorpr>ZFallbackAsyncAdaptedQueuerr6r6r6r7rvsrvc@sXeZdZdZddœdd„Zdddœd    d
„Zddœd d „Zddœd d„Zddœdd„ZdS)ÚNullPoolaQA 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.
 
    rirDcCsdS)Nrwr6rPr6r6r7reszNullPool.statusrr8r9cCs | ¡dSrl)rArBr6r6r7rCszNullPool._do_return_conncCs| ¡Srl)rMrPr6r6r7rHszNullPool._do_getc
Cs6|j d¡|j|j|j|j|j|j|j|j    |j
dS)NrQ)rSrTrUrVrRrWrX) rYrZr[r\r_rTr`rar^rbrcrPr6r6r7rds øzNullPool.recreatecCsdSrlr6rPr6r6r7rh+szNullPool.disposeN)    rnrorprqrerCrHrdrhr6r6r6r7rws  rwc@sŒeZdZdZdZdddddœdd    „Zdd
œd d „Zd d
œdd„Zd d
œdd„Zdd
œdd„Z    dd dœdd„Z
dd
œdd„Z dd
œdd„Z dS) ÚSingletonThreadPoola©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`.
 
    Fr r#r$r)r'r(r,cKs6tj||f|Žt ¡|_t ¡|_tƒ|_||_dSrl)    rr.r2ÚlocalÚ_connÚ_fairyÚsetÚ
_all_connsrJ)r5r'r(r,r6r6r7r.Ps
 
 
zSingletonThreadPool.__init__rDc Cs:|j d¡|j|j|j|j|j|j|j|j    |j
|j d    S)NrQ)r(rSrTrRrUrVrWrX) rYrZr[r\rJr_rTr^r`rarbrcrPr6r6r7rd\s ÷zSingletonThreadPool.recreater8c    Cs<|jD]&}z | ¡Wqtk
r*YqXq|j ¡dS)zDispose of this pool.N)r}rAÚ    ExceptionÚclearrfr6r6r7rhjs 
 zSingletonThreadPool.disposecCs(t|jƒ|jkr$|j ¡}| ¡qdSrl)Úlenr}rJÚpoprA©r5Úcr6r6r7Ú_cleanupws
zSingletonThreadPool._cleanupricCsdt|ƒt|jƒfS)Nz"SingletonThreadPool id:%d size: %d)Úidr€r}rPr6r6r7re|sþzSingletonThreadPool.statusrr9cCs$z
|j`Wntk
rYnXdSrl)r{ÚcurrentÚAttributeErrorrBr6r6r7rC‚s
z#SingletonThreadPool._do_return_conncCs‚z.trtt|j ¡ƒ}n
|j ¡}|r,|WSWntk
rBYnX| ¡}t |¡|j_t    |j
ƒ|j krr|  ¡|j
  |¡|Srl)r    rrrzr†r‡rMÚweakrefÚrefr€r}rJr„Úaddr‚r6r6r7rHˆs
 
 zSingletonThreadPool._do_getrcCsHztt|j ¡ƒ}Wntk
r(YnX|dk    r:| ¡St ||j¡Srl)rr r{r†r‡Z_checkout_existingZ    _checkout©r5Úrecr6r6r7Úconnect™szSingletonThreadPool.connectN)r ) rnrorprqrrr.rdrhr„rerCrHrr6r6r6r7rx/sý  rxc@sŠeZdZdZejddœdd„ƒZddœdd„Zd    dœd
d „Zddœd d „Z    dd    dœdd„Z
ddœdd„Z dd    dœdd„Z ddœdd„Z dS)Ú
StaticPoolaA 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.
 
 
    rrDcCst|ƒSrlrrPr6r6r7Ú
connection²szStaticPool.connectionricCsdS)NrŽr6rPr6r6r7re¶szStaticPool.statusr8cCs,d|jkr(|jjdk    r(|j ¡|jd=dS©Nr)Ú__dict__rÚdbapi_connectionrArPr6r6r7rh¹s ÿ
þ
zStaticPool.disposec
Cs6|j d¡|j|j|j|j|j|j|j|j    |j
dS)NrQ)r'rSrVrRrTrUrWrX) rYrZr[r\r_rar^rTr`rbrcrPr6r6r7rdÁs øzStaticPool.recreate)Úother_static_poolr;csdddœ‡fdd„ }||_dS)Nrr)rŒr;csˆjj}|dk    st‚|Srl)rr’ÚAssertionError)rŒrg©r“r6r7r'Ñs z*StaticPool._transfer_from.<locals>.creator)Z_invoke_creator)r5r“r'r6r•r7Ú_transfer_fromÎszStaticPool._transfer_fromrcCs
tƒ‚dSrl)ÚNotImplementedErrorrPr6r6r7rMØszStaticPool._create_connectionr9cCsdSrlr6rBr6r6r7rCÛszStaticPool._do_return_conncCs |j}| ¡r|jd=|j}|Sr)rZ_is_hard_or_soft_invalidatedr‘r‹r6r6r7rHÞs
zStaticPool._do_getN)rnrorprqrZmemoized_propertyrrerhrdr–rMrCrHr6r6r6r7rާs     
rŽc@szeZdZUdZded<ded<dddœdd    „Zd
d œd d „Zdddœdd„Zdd œdd„Zdd œdd„Z    dd œdd„Z
dS)Ú AssertionPoola    A :class:`_pool.Pool` that allows at most one checked out connection at
    any given time.
 
    This will raise an exception if more than one connection is checked out
    at a time.  Useful for debugging code that is using more connections
    than desired.
 
    zOptional[ConnectionPoolEntry]rzzOptional[List[str]]Ú_checkout_tracebackr)Úargsr,cOs6d|_d|_| dd¡|_d|_tj|f|ž|ŽdS)NFZstore_tracebackT)rzÚ _checked_outrÚ_store_tracebackr™rr.)r5ršr,r6r6r7r.õs
zAssertionPool.__init__rirDcCsdS)Nr˜r6rPr6r6r7reüszAssertionPool.statusrr8r9cCs&|jstdƒ‚d|_||jks"t‚dS)Nzconnection is not checked outF)r›r”rzrBr6r6r7rCÿszAssertionPool._do_return_conncCsd|_|jr|j ¡dSr<)r›rzrArPr6r6r7rhszAssertionPool.disposec
Cs6|j d¡|j|j|j|j|j|j|j|j    |j
dS)NrQ)rTrRrSrVrUrWrX) rYrZr[r\rTr^r_rar`rbrcrPr6r6r7rd
s øzAssertionPool.recreatecCs^|jr2|jr"dd t|jƒ¡}nd}td|ƒ‚|jsB| ¡|_d|_|jrXt     ¡|_|jS)Nz at:
%sÚz!connection is already checked outT)
r›r™Újoinrr”rzrMrœÚ    tracebackÚ format_stack)r5Úsuffixr6r6r7rHsÿ 
 
zAssertionPool._do_getN) rnrorprqrtr.rerCrhrdrHr6r6r6r7r˜çs
     r˜))rqÚ
__future__rr2rŸÚtypingrrrrrrr    r
rˆÚbaser r rrrrrrrrrrrr>Z util.typingrZengine.interfacesrrrurvrwrxrŽr˜r6r6r6r7Ú<module>    sH                       N    (x@