HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/kombu/__pycache__/resource.cpython-310.pyc
o

'we7�@s�dZddlmZddlZddlmZddlmZddlmZ	ddl
mZdd	lm
Z
dd
lmZddlmZer>ddlmZd
d�ZGdd�de	�ZGdd�d�ZdS)z%Generic resource pool implementation.�)�annotationsN)�deque)�Empty)�	LifoQueue)�
TYPE_CHECKING�)�
exceptions)�register_after_fork)�lazy)�
TracebackTypecCs$z|��WdStyYdSw�N)�force_close_all�	Exception)�resource�r�G/home/arjun/projects/env/lib/python3.10/site-packages/kombu/resource.py�_after_fork_cleanup_resources
�rc@seZdZdZdd�ZdS)rz#Last in first out version of Queue.cCst�|_dSr)r�queue)�self�maxsizerrr�_init�zLifoQueue._initN)�__name__�
__module__�__qualname__�__doc__rrrrrrsrc@s�eZdZdZejZdZd&dd�Zdd�Zdd	�Z	d'd
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd(dd�Zd)dd�Zedd ��Zejd!d ��Zej�d"�rfe
ZeZd#Zd$d�Z
d%d�ZdSdS)*�ResourcezPool of resources.FNcCs^||_|pd|_d|_|dur|n|j|_t�|_t�|_|jr)tdur)t|t	�|�
�dS)NrF)�_limit�preload�_closed�close_after_forkr�	_resource�set�_dirtyr	r�setup)r�limitrr rrr�__init__(s
��
zResource.__init__cCstd��)Nzsubclass responsibility)�NotImplementedError�rrrrr$7szResource.setupcCs6|jrt|j�|jkr|�|j��|j�|���dSr)r%�lenr#�
LimitExceededr!�
put_nowait�newr(rrr�_add_when_empty:szResource._add_when_emptycs��jrtd���jrM	z
�jj||d��Wn
ty"���Yn)wz�����WntyCt	�t
�r=�j���������w�j
���nqn���������fdd�}|�_�S)a�Acquire resource.

        Arguments:
        ---------
            block (bool): If the limit is exceeded,
                then block until there is an available item.
            timeout (float): Timeout to wait
                if ``block`` is true.  Default is :const:`None` (forever).

        Raises
        ------
            LimitExceeded: if block is false and the limit has been exceeded.
        zAcquire on closed poolr)�block�timeoutcs����dS)a'Release resource so it can be used by another thread.

            Warnings:
            --------
                The caller is responsible for discarding the object,
                and to never use the resource again.  A new resource must
                be acquired if so needed.
            N)�releaser��Rrrrr0hs	z!Resource.acquire.<locals>.release)r�RuntimeErrorr%r!�getrr-�prepare�
BaseException�
isinstancer
r+r0r#�addr,)rr.r/r0rr1r�acquireBs4�

���
zResource.acquirecCs|Srr�rrrrrr5v�zResource.preparecCs|��dSr)�closer:rrr�close_resourceyrzResource.close_resourcecC�dSrrr:rrr�release_resource|r;zResource.release_resourcecCs |jr	|j�|�|�|�dS)zqReplace existing resource with a new instance.

        This can be used in case of defective resources.
        N)r%r#�discardr=r:rrr�replaceszResource.replacecCs:|jr|j�|�|j�|�|�|�dS|�|�dSr)r%r#r@r!r+r?r=r:rrrr0�s
zResource.releasecCr>rrr:rrr�collect_resource�r;zResource.collect_resourcecCs�|jrdSd|_|j}|j}	z|��}Wn	tyYnwz|�|�Wn	ty/Ynwq	z|j��}Wn
tyCYdSwz|�|�Wn	tyTYnwq2)z�Close and remove all resources in the pool (also those in use).

        Used to close resources from parent processes after fork
        (e.g. sockets/connections).
        NT)	rr#r!�pop�KeyErrorrB�AttributeErrorr�
IndexError)r�dirtyr�dres�resrrrr
�s:���	���zResource.force_close_allcCs�|j}|jr"d|kr|jkr"nn|s"|s td�|j|���d}||_|r7z|��Wn	ty6Ynw|��||krI|j|dkd�dSdS)Nrz,Can't shrink pool when in use: was={} now={}T)�collect)rr#r3�formatr
rr$�_shrink_down)rr%�force�
ignore_errors�reset�
prev_limitrrr�resize�s($����zResource.resizeTcCs�Gdd�d�}|j}t|d|���-t|j�|jkr6|j��}|r&|�|�t|j�|jksWd�dSWd�dS1sAwYdS)Nc@seZdZdd�Zddd�Zd
S)z#Resource._shrink_down.<locals>.NoopcSr>rrr(rrr�	__enter__�r;z-Resource._shrink_down.<locals>.Noop.__enter__�exc_type�type�exc_valr�exc_tbr�return�NonecSr>rr)rrSrUrVrrr�__exit__�sz,Resource._shrink_down.<locals>.Noop.__exit__N)rSrTrUrrVrrWrX)rrrrRrYrrrr�Noop�srZ�mutex)r!�getattrr)rr%�popleftrB)rrJrZrr2rrrrL�s

��"�zResource._shrink_downcCs|jSr)rr(rrrr%�szResource.limitcCs|�|�dSr)rQ)rr%rrrr%�s�KOMBU_DEBUG_POOLrcOs�ddl}|jd}|_td|�d|jj���|j|i|��}||_td|�d|jj���t|d�s7g|_|j�	|�
��|S)Nrr�+z	 ACQUIRE �-�acquired_by)�	traceback�_next_resource_id�print�	__class__r�
_orig_acquire�_resource_id�hasattrra�append�format_stack)r�args�kwargsrb�id�rrrrr9�s
cCsR|j}td|�d|jj���|�|�}td|�d|jj���|jd8_|S)Nr_z	 RELEASE r`r)rgrdrer�
_orig_releaserc)rrrmrnrrrr0�s
)NNN)FN)FFF)T)rrrrrr*r r&r$r-r9r5r=r?rAr0rBr
rQrL�propertyr%�setter�os�environr4rfrorcrrrrr!s8

4	
!


�r)r�
__future__rrr�collectionsrrrr�
_LifoQueue�typingr�r�utils.compatr	�utils.functionalr
�typesrrrrrrr�<module>s