Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/pool/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/pool/__pycache__/impl.cpython-311.pyc

�

�܋fn:���dZddlZddlZddlmZddlmZddlmZddlmZdd	lm	Z	dd
l	m
Z
ddl	mZddl	m
Z
Gd
�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZdS)zPool implementation classes.

�N�)�_ConnectionFairy��_ConnectionRecord)�Pool�)�exc)�util)�chop_traceback)�queue)�	threadingc�j�eZdZdZ				dd�Zd�Zd�Zd	�Zd
�Zd�Z	d�Z
d
�Zd�Zd�Z
d�Zd�Zd�ZdS)�	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.

    ��
�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_queue�Queue�_pool�	_overflow�
_max_overflow�_timeoutr
�Lock�_overflow_lock)�self�creator�	pool_size�max_overflow�timeoutr�kws       �K/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/pool/impl.pyrzQueuePool.__init__$sf��z	
�
�d�G�*�*�r�*�*�*��%�i�(�C�C�C��
��Y����)�����
�'�n�.�.�����c���	|j�|d��dS#tj$rF	|���|���YdS#|���wxYwwxYw�NF)r�putr�Full�close�
_dec_overflow�r�conns  r$�_do_return_connzQueuePool._do_return_connhs���	%��J�N�N�4��'�'�'�'�'����	%�	%�	%�
%��
�
�����"�"�$�$�$�$�$�$���"�"�$�$�$�$����		%���s ��A4�A�A4�A0�0A4c��|jdk}	|o|j|jk}|j�||j��S#t
j$rYnwxYw|rk|j|jkr[|s|���Stj	d|�
��|���|jfzd����|���r_	|�
��S#tj��5|���ddd��n#1swxYwYYdSYdSxYw|���S)N���zPQueuePool limit of size %d overflow %d reached, connection timed out, timeout %d�3o7r)�code)rrr�getrr�Empty�_do_getr	�TimeoutError�size�overflow�
_inc_overflow�_create_connectionr
�safe_reraiser+)r�use_overflow�waits   r$r5zQueuePool._do_getqs����)�B�.��	��H�D�N�d�6H�$H�D��:�>�>�$��
�6�6�6����	�	�	�
�D�		����
�		�D�N�d�.@�@�@��
��|�|�~�~�%��&�7��y�y�{�{�D�M�M�O�O�T�]�C�D� �	���������	"�
)��.�.�0�0�0��
)��&�(�(�)�)��&�&�(�(�(�)�)�)�)�)�)�)�)�)�)�)����)�)�)�)�)�)�)�)�)�)�����<�<�>�>�!s?�1?�A�A�C*�*D1�?D �D1� D$	�$D1�'D$	�(D1c���|jdkr|xjdz
c_dS|j5|j|jkr|xjdz
c_	ddd��dS	ddd��dS#1swxYwYdS)Nr0rTF�rrr�rs r$r9zQueuePool._inc_overflow�s������#�#��N�N�a��N�N��4�
�
 �	�	��~�� 2�2�2����!�#����	�	�	�	�	�	�	�	�
�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�"A"�A"�"A&�)A&c��|jdkr|xjdzc_dS|j5|xjdzc_	ddd��dS#1swxYwYdS)Nr0rTr?r@s r$r+zQueuePool._dec_overflow�s������#�#��N�N�a��N�N��4�
�
 �	�	��N�N�a��N�N��	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�A�A�Ac��|j�d��|�|j|jj|j|j|jj|j	|j
|j|j|j
|j|j|j��
�
S)N�Pool recreating)r r!�pre_pingrr"�recycle�echo�logging_name�use_threadlocal�reset_on_return�	_dispatch�dialect)�logger�info�	__class__�_creatorr�maxsizer�	_pre_pingrr�_recyclerF�_orig_logging_name�_use_threadlocal�_reset_on_return�dispatch�_dialectr@s r$�recreatezQueuePool.recreate�s������*�+�+�+��~�~��M��j�(��+��^��Z�(��M��M����0� �1� �1��m��M��
�
�	
r%c�&�		|j�d��}|���n#tj$rYnwxYw�Fd|���z
|_|j�d|�	����dS)NTFrzPool disposed. %s)
rr3r*rr4r7rrLrM�statusr,s  r$�disposezQueuePool.dispose�s���	�
��z�~�~�e�,�,���
�
�������#�
�
�
���
����		��T�Y�Y�[�[��������,�d�k�k�m�m�<�<�<�<�<s�.2�A�Ac��d|���|���|���|���fzS)Nz_Pool size: %d  Connections in pool: %d Current Overflow: %d Current Checked out connections: %d)r7�	checkedinr8�
checkedoutr@s r$rZzQueuePool.status�sH��
��	�	������ � ��
�
������!�!�	�
�
	
r%c��|jjS�N)rrPr@s r$r7zQueuePool.size�s
���z�!�!r%c��|jSr`)rr@s r$r"zQueuePool.timeout�s
���}�r%c�4�|j���Sr`)r�qsizer@s r$r]zQueuePool.checkedin�s���z���!�!�!r%c��|jSr`)rr@s r$r8zQueuePool.overflow�s
���~�r%c�^�|jj|j���z
|jzSr`)rrPrcrr@s r$r^zQueuePool.checkedout�s'���z�!�D�J�$4�$4�$6�$6�6���G�Gr%N)rrrF)�__name__�
__module__�__qualname__�__doc__rr.r5r9r+rXr[rZr7r"r]r8r^�r%r$rrs�������������
B/�B/�B/�B/�H%�%�%�"�"�"�>	�	�	����
�
�
�$	=�	=�	=�
�
�
�"�"�"����"�"�"����H�H�H�H�Hr%rc�0�eZdZdZd�Zd�Zd�Zd�Zd�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.

    c��dS)Nrlrjr@s r$rZzNullPool.status�s���zr%c�.�|���dSr`)r*r,s  r$r.zNullPool._do_return_conn�s���
�
�����r%c�*�|���Sr`)r:r@s r$r5zNullPool._do_get�s���&�&�(�(�(r%c���|j�d��|�|j|j|j|j|j|j|j	|j
|j��	�	S)NrC)rErFrGrHrIrDrJrK)rLrMrNrOrRrFrSrTrUrQrVrWr@s r$rXzNullPool.recreate�sd������*�+�+�+��~�~��M��M����0� �1� �1��^��m��M��

�

�
	
r%c��dSr`rjr@s r$r[zNullPool.dispose����r%N)	rfrgrhrirZr.r5rXr[rjr%r$rlrl�si������	�	�������)�)�)�

�

�

�
�
�
�
�
r%rlc�J�eZdZdZd
d�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�ZdS)�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`.

    rc��tj||fi|��tj��|_tj��|_t
��|_||_dSr`)	rrr
�local�_conn�_fairy�set�
_all_connsr7)rrr r#s    r$rzSingletonThreadPool.__init__%sP���
�d�G�*�*�r�*�*�*��_�&�&��
��o�'�'����%�%�����	�	�	r%c���|j�d��|�|j|j|j|j|j|j|j	|j
|j|j��
�
S)NrC)	r rErFrDrGrHrIrJrK)
rLrMrNrOr7rRrFrQrSrTrUrVrWr@s r$rXzSingletonThreadPool.recreate,si������*�+�+�+��~�~��M��i��M����^��0� �1� �1��m��M��
�
�	
r%c��|jD]'}	|����#t$rY�$wxYw|j���dS)zDispose of this pool.N)rzr*�	Exception�clearr,s  r$r[zSingletonThreadPool.dispose;sg���O�	�	�D�
��
�
�������
�
�
���
����
	
��������s� �
-�-c���t|j��|jkrL|j���}|���t|j��|jk�JdSdSr`)�lenrzr7�popr*�r�cs  r$�_cleanupzSingletonThreadPool._cleanupHs^���$�/�"�"�d�i�/�/���#�#�%�%�A�
�G�G�I�I�I��$�/�"�"�d�i�/�/�/�/�/�/r%c�N�dt|��t|j��fzS)Nz"SingletonThreadPool id:%d size: %d)�idr�rzr@s r$rZzSingletonThreadPool.statusMs*��3��t�H�H���� � �7
�
�	
r%c��dSr`rjr,s  r$r.z#SingletonThreadPool._do_return_connSrrr%c�^�	|j���}|r|Sn#t$rYnwxYw|���}t	j|��|j_t
|j��|jkr|�	��|j�
|��|Sr`)rw�current�AttributeErrorr:�weakref�refr�rzr7r��addr�s  r$r5zSingletonThreadPool._do_getVs���	��
�"�"�$�$�A��
���
���	�	�	��D�	�����#�#�%�%��$�[��^�^��
���t����4�9�,�,��M�M�O�O�O�����A�����s� �
-�-c��	|j���}|�|���Sn#t$rYnwxYwt	j||j��Sr`)rxr��_checkout_existingr�r�	_checkout)r�recs  r$�connectzSingletonThreadPool.connectdsq��	0��+�%�%�'�'�C����-�-�/�/�/����	�	�	��D�	���� �)�$���<�<�<s�2�
?�?c�b�	|j`n#t$rYnwxYw|�|��dSr`)rxr�r�r.)r�records  r$�_return_connz SingletonThreadPool._return_connpsL��	���#�#���	�	�	��D�	�������V�$�$�$�$�$s�
�
�N)r)
rfrgrhrirrXr[r�rZr.r5r�r�rjr%r$rtrts���������:����

�

�

� � � ����

�
�
�
�
�
����
=�
=�
=�%�%�%�%�%r%rtc�v�eZdZdZejd���Zejd���Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
S)�
StaticPoola.A 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 not
    currently supported by this Pool implementation but may be implemented
    in a future release.

    c�*�|���Sr`)rOr@s r$rwzStaticPool._conn�s���}�}���r%c� �t|��Sr`rr@s r$�
connectionzStaticPool.connection�s�� ��&�&�&r%c��dS)Nr�rjr@s r$rZzStaticPool.status�s���|r%c�\�d|jvr"|j���d|_dSdS)Nrw)�__dict__rwr*r@s r$r[zStaticPool.dispose�s6���d�m�#�#��J�������D�J�J�J�$�#r%c���|j�d��|�|j|j|j|j|j|j|j	|j
|j��	�	S)NrC)	rrErHrIrDrFrGrJrK)rLrMrNrOrRrTrUrQrFrSrVrWr@s r$rXzStaticPool.recreate�sd������*�+�+�+��~�~��M��M� �1� �1��^����0��m��M��

�

�
	
r%c��|jSr`)rwr@s r$r:zStaticPool._create_connection�s
���z�r%c��dSr`rjr,s  r$r.zStaticPool._do_return_conn�rrr%c��|jSr`)r�r@s r$r5zStaticPool._do_get�s
����r%N)rfrgrhrir
�memoized_propertyrwr�rZr[rXr:r.r5rjr%r$r�r�xs���������
�������
��'�'���'�������

�
�
����
�
�
�����r%r�c�6�eZdZdZd�Zd�Zd�Zd�Zd�Zd�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.

    c��d|_d|_|�dd��|_d|_tj|g|�Ri|��dS)NF�store_tracebackT)rw�_checked_outr��_store_traceback�_checkout_tracebackrr)r�argsr#s   r$rzAssertionPool.__init__�sV����
�!��� "���'8�$� ?� ?���#'�� ��
�d�(�T�(�(�(�R�(�(�(�(�(r%c��dS)Nr�rjr@s r$rZzAssertionPool.status�s���r%c�V�|jstd���d|_||jusJ�dS)Nzconnection is not checked outF)r��AssertionErrorrwr,s  r$r.zAssertionPool._do_return_conn�s>��� �	B� �!@�A�A�A�!����t�z�!�!�!�!�!�!r%c�X�d|_|jr|j���dSdSr')r�rwr*r@s r$r[zAssertionPool.dispose�s8��!����:�	��J��������	�	r%c
��|j�d��|�|j|j|j|j|j|j|j	|j
���S)NrC)rFrDrErIrGrJrK)rLrMrNrOrFrQrRrUrSrVrWr@s r$rXzAssertionPool.recreate�s^������*�+�+�+��~�~��M����^��M� �1��0��m��M��	
�	
�		
r%c�6�|jrF|jr+dd�t|j����z}nd}t	d|z���|js|���|_d|_|jrtj	��|_|jS)Nz at:
%s�z!connection is already checked outT)
r�r��joinrr�rwr:r��	traceback�format_stack)r�suffixs  r$r5zAssertionPool._do_get�s�����	O��'�
�#�b�g�g�"�4�#;�<�<�'�'������ �!D�v�!M�N�N�N��z�	3��0�0�2�2�D�J� ���� �	@�'0�'=�'?�'?�D�$��z�r%N)
rfrgrhrirrZr.r[rXr5rjr%r$r�r��sx��������)�)�)����"�"�"����

�
�
�����r%r�)rir�r��baserrrr�r	r
rrrr
rrlrtr�r�rjr%r$�<module>r�s�������������"�"�"�"�"�"�#�#�#�#�#�#�������������������!�!�!�!�!�!�&�&�&�&�&�&�������@H�@H�@H�@H�@H��@H�@H�@H�F&
�&
�&
�&
�&
�t�&
�&
�&
�Ro%�o%�o%�o%�o%�$�o%�o%�o%�d0�0�0�0�0��0�0�0�f=�=�=�=�=�D�=�=�=�=�=r%

Hacked By AnonymousFox1.0, Coded By AnonymousFox