Q-В dZddlZddlZddlmZddlmZddlmZddlmZdd lm Z dd l m Z dd l m Z dd l m Z Gd deZGddeZGddeZGddeZGddeZdS)zPool implementation classes. N)_ConnectionFairy_ConnectionRecord)Pool)exc)util)chop_traceback)queue) threadingcjeZdZdZ ddZdZdZd Zd Zd Z d Z d Z dZ dZ dZdZdZdS) QueuePoolzA :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.  Fc tj||fi|tj|||_d|z |_||_||_tj |_ 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. :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. )use_liforN) r__init__ sqla_queueQueue_pool _overflow _max_overflow_timeoutr Lock_overflow_lock)selfcreator pool_size max_overflowtimeoutrkws /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/sqlalchemy/pool/impl.pyrzQueuePool.__init__$sfz dG**r***%i(CCC Y) 'n..c |j|ddS#tj$rF ||YdS#|wxYwwxYwNF)rputrFullclose _dec_overflowrconns r$_do_return_connzQueuePool._do_return_connhs % JNN4 ' ' ' ' ' % % % % ""$$$$$$""$$$$  %s A4AA4A00A4c|jdk} |o|j|jk}|j||jS#t j$rYnwxYw|rk|j|jkr[|s|Stj d| | |jfzd| r_ | S#tj5|dddn#1swxYwYYdSYdSxYw|S)NzPQueuePool limit of size %d overflow %d reached, connection timed out, timeout %d3o7r)code)rrrgetrrEmpty_do_getr TimeoutErrorsizeoverflow _inc_overflow_create_connectionr safe_reraiser+)r use_overflowwaits r$r5zQueuePool._do_getqs)B.  HDNd6H$HD:>>$ 66 6    D    DNd.@@@ ||~~%&7yy{{DMMOOT]CD       " )..000 )&(())&&((()))))))))))))))))))))<<>> !s?1?AAC**D1?D  D1 D$ $D1'D$ (D1c|jdkr|xjdz c_dS|j5|j|jkr|xjdz c_ ddddS ddddS#1swxYwYdS)Nr0rTFrrrrs r$r9zQueuePool._inc_overflows   # # NNa NN4    ~ 222!#                            s"A"A""A&)A&c|jdkr|xjdzc_dS|j5|xjdzc_ ddddS#1swxYwYdS)Nr0rTr?r@s r$r+zQueuePool._dec_overflows   # # NNa NN4     NNa NN                  sAA Ac|jd||j|jj|j|j|jj|j |j |j |j |j |j|j|j S)NPool recreating) r r!pre_pingrr"recycleecho logging_nameuse_threadlocalreset_on_return _dispatchdialect)loggerinfo __class___creatorrmaxsizer _pre_pingrr_recyclerF_orig_logging_name_use_threadlocal_reset_on_returndispatch_dialectr@s r$recreatezQueuePool.recreates *+++~~ Mj(+^Z(MM0 1 1mM   r%c& |jd}|n#tj$rYnwxYwFd|z |_|jd| dS)NTFrzPool disposed. %s) rr3r*rr4r7rrLrMstatusr,s r$disposezQueuePool.disposes  z~~e,, #      TYY[[ ,dkkmm<<<<      $ = = =    """"""HHHHHr%rc0eZdZdZdZdZdZdZdZdS)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. cdS)Nrlrjr@s r$rZzNullPool.statusszr%c.|dSr`)r*r,s r$r.zNullPool._do_return_conns r%c*|Sr`)r:r@s r$r5zNullPool._do_gets&&(((r%c |jd||j|j|j|j|j|j|j |j |j  S)NrC)rErFrGrHrIrDrJrK) rLrMrNrOrRrFrSrTrUrQrVrWr@s r$rXzNullPool.recreatesd *+++~~ MM0 1 1^mM   r%cdSr`rjr@s r$r[zNullPool.dispose r%N) rfrgrhrirZr.r5rXr[rjr%r$rlrlsi  )))         r%rlcJeZdZdZd dZdZdZdZdZdZ d Z d Z d Z d S)SingletonThreadPoolaA 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`. rc tj||fi|tj|_tj|_t |_||_dSr`) rrr local_conn_fairyset _all_connsr7)rrr r#s r$rzSingletonThreadPool.__init__%sP dG**r***_&& o'' %% r%c |jd||j|j|j|j|j|j|j |j |j |j  S)NrC) r rErFrDrGrHrIrJrK) rLrMrNrOr7rRrFrQrSrTrUrVrWr@s r$rXzSingletonThreadPool.recreate,si *+++~~ MiM^0 1 1mM   r%c|jD]'} |#t$rY$wxYw|jdS)zDispose of this pool.N)rzr* Exceptionclearr,s r$r[zSingletonThreadPool.dispose;sgO  D       s   --ct|j|jkrL|j}|t|j|jkJdSdSr`)lenrzr7popr*rcs r$_cleanupzSingletonThreadPool._cleanupHs^$/""di//##%%A GGIII$/""di//////r%cNdt|t|jfzS)Nz"SingletonThreadPool id:%d size: %d)idrrzr@s r$rZzSingletonThreadPool.statusMs*3 tHH  7   r%cdSr`rjr,s r$r.z#SingletonThreadPool._do_return_connSrrr%c^ |j}|r|Sn#t$rYnwxYw|}t j||j_t |j|jkr| |j ||Sr`) rwcurrentAttributeErrorr:weakrefrefrrzr7raddrs r$r5zSingletonThreadPool._do_getVs  ""$$A      D   # # % %$[^^  t  49 , , MMOOO As  --c |j}||Sn#t$rYnwxYwt j||jSr`)rxr_checkout_existingrr _checkout)rrecs r$connectzSingletonThreadPool.connectdsq 0+%%''C--///    D   )$ <<  B !@AA A!tz!!!!!!r%cXd|_|jr|jdSdSr')rrwr*r@s r$r[zAssertionPool.disposes8! :  J         r%c |jd||j|j|j|j|j|j|j |j S)NrC)rFrDrErIrGrJrK) rLrMrNrOrFrQrRrUrSrVrWr@s r$rXzAssertionPool.recreates^ *+++~~ M^M 10mM   r%c6|jrF|jr+ddt|jz}nd}t d|z|js||_d|_|jrtj |_|jS)Nz at: %sz!connection is already checked outT) rrjoinr rrwr:r traceback format_stack)rsuffixs r$r5zAssertionPool._do_gets   O' #bgg"4#;<<'' !Dv!MNN Nz 30022DJ    @'0'='?'?D $zr%N) rfrgrhrirrZr.r[rXr5rjr%r$rrsx)))"""     r%r)rirrbaserrrrr r r r rr rrlrtrrrjr%r$rs""""""######!!!!!!&&&&&&@H@H@H@H@H@H@H@HF& & & & & t& & & Ro%o%o%o%o%$o%o%o%d00000000f=====D=====r%