Hacked By AnonymousFox
�
�܋fn: � � � d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ dd lm Z dd
l m
Z
ddl mZ ddl m
Z
G d
� de� � Z G d� de� � Z G d� de� � Z G d� de� � Z G d� de� � ZdS )zPool implementation classes.
� N� )�_ConnectionFairy��_ConnectionRecord)�Pool� )�exc)�util)�chop_traceback)�queue)� threadingc �j � e Zd ZdZ dd�Zd� Zd� Zd � Zd
� Zd� Z d� Z
d
� Zd� Zd� 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 �� � t j | |fi |�� t j ||�� � | _ d|z
| _ || _ || _ t j � � | _
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_lifor N)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.pyr zQueuePool.__init__$ sf � �z
�
�d�G�*�*�r�*�*�*��%�i�(�C�C�C��
��Y����)�����
�'�n�.�.����� c �� � | j � |d� � d S # t j $ rF |� � � | � � � Y d S # | � � � w xY ww xY w�NF)r �putr �Full�close�
_dec_overflow�r �conns r$ �_do_return_connzQueuePool._do_return_connh s� � � %��J�N�N�4��'�'�'�'�'���� %� %� %�
%��
�
�����"�"�$�$�$�$�$�$���"�"�$�$�$�$���� %���s � �A4�A�A4�A0�0A4c � � | j dk } |o| j | j k }| j � || j � � S # t
j $ r Y nw xY w|rk| j | j k r[|s| � � � S t j d| �
� � | � � � | j fz d�� � �| � � � r_ | �
� � S # t j � � 5 | � � � d d d � � n# 1 swxY w Y Y d S Y d S xY w| � � � S )N���zPQueuePool limit of size %d overflow %d reached, connection timed out, timeout %d�3o7r)�code)r r r �getr r �Empty�_do_getr �TimeoutError�size�overflow�
_inc_overflow�_create_connectionr
�safe_reraiser+ )r �use_overflow�waits r$ r5 zQueuePool._do_getq s� � ��)�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 �� � | j dk r| xj dz
c_ dS | j 5 | j | j k r| xj dz
c_ d d d � � dS d d d � � dS # 1 swxY w Y d S )Nr0 r TF�r r r �r s r$ r9 zQueuePool._inc_overflow� s� � ����#�#��N�N�a��N�N��4�
�
� � ��~�� 2�2�2����!�#���� � � � � � � � �
� � � � � � � � � � � � ���� � � � � � s �"A"�A"�"A&�)A&c � � | j dk r| xj dz c_ dS | j 5 | xj dz c_ d d d � � dS # 1 swxY w Y d S )Nr0 r Tr? 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 | j j | j | j | j j | j | j
| j | j | j
| j | j | j ��
�
S )N�Pool recreating)r r! �pre_pingr r"