o
    —¨Êh‡  ã                   @  s  d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	lmZ dd
lmZ dZdgZg Zeƒ Zej d¡Zdd„ ZG dd„ deƒZG dd„ deƒZdd„ ZG dd„ deƒZeeed�ƒZG dd„ deƒZeeed�ƒZdd„ Z dd„ Z!d$d d!„Z"d"d#„ Z#dS )%zPublic resource pools.é    )ÚannotationsN)Úchainé   )ÚResource)ÚProducer)ÚEqualityDict)Úregister_after_fork)Úlazy)ÚProducerPoolÚ	PoolGroupÚregister_groupÚconnectionsÚ	producersÚ	get_limitÚ	set_limitÚreseté
   ÚKOMBU_DISABLE_LIMIT_PROTECTIONc                 C  s   |   ¡  d S ©N)Úclear©Úgroup© r   ú=/var/www/html/env/lib/python3.10/site-packages/kombu/pools.pyÚ_after_fork_cleanup_group   ó   r   c                      sd   e Zd ZdZeZdZ‡ fdd„Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Z‡ fdd„Z‡  ZS )r
   z*Pool of :class:`kombu.Producer` instances.Tc                   s0   || _ | dd ¡p| j| _tƒ j|i |¤Ž d S )Nr   )r   Úpopr   ÚsuperÚ__init__)Úselfr   ÚargsÚkwargs©Ú	__class__r   r   r       s   zProducerPool.__init__c                 C  s   | j jdd�S )NT)Úblock)r   Úacquire©r   r   r   r   Ú_acquire_connection%   s   z ProducerPool._acquire_connectionc                 C  s.   |   ¡ }z|  |¡W S  ty   | ¡  ‚ w r   )r'   r   ÚBaseExceptionÚrelease)r   Úconnr   r   r   Úcreate_producer(   s   þzProducerPool.create_producerc                 C  s
   t | jƒS r   )r	   r+   r&   r   r   r   Únew0   s   
zProducerPool.newc                 C  s.   | j rt| j ƒD ]}| j |  ¡ ¡ qd S d S r   )ÚlimitÚrangeÚ	_resourceÚ
put_nowaitr,   )r   Ú_r   r   r   Úsetup3   s
   þzProducerPool.setupc                 C  s   d S r   r   ©r   Úresourcer   r   r   Úclose_resource8   s   zProducerPool.close_resourcec                 C  sN   t |ƒr|ƒ }|jd u r%|  ¡ }z| |¡ W |S  ty$   | ¡  ‚ w |S r   )ÚcallableÚ_channelr'   Úreviver(   r)   )r   Úpr*   r   r   r   Úprepare;   s   
ýþzProducerPool.preparec                   s&   |j r|j  ¡  d |_tƒ  |¡ d S r   )Ú__connection__r)   Úchannelr   r3   r"   r   r   r)   G   s   
zProducerPool.release)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclose_after_forkr   r'   r+   r,   r2   r5   r:   r)   Ú__classcell__r   r   r"   r   r
      s    r
   c                   @  s*   e Zd ZdZd
dd„Zdd„ Zdd	„ ZdS )r   zCollection of resource pools.NTc                 C  s0   || _ || _| jrtd urt| tƒ d S d S d S r   )r-   rA   r   r   )r   r-   rA   r   r   r   r   Q   s
   ÿzPoolGroup.__init__c                 C  s   t dƒ‚)Nz!PoolGroups must define ``create``)ÚNotImplementedError)r   r4   r-   r   r   r   ÚcreateW   s   zPoolGroup.createc                 C  s,   | j }|tu r
tƒ }|  ||¡ }| |< |S r   )r-   Úuse_global_limitr   rD   )r   r4   r-   Úkr   r   r   Ú__missing__Z   s
   zPoolGroup.__missing__)NT)r=   r>   r?   r@   r   rD   rG   r   r   r   r   r   N   s
    
r   c                 C  s   t  | ¡ | S )z*Register group (can be used as decorator).)Ú_groupsÚappendr   r   r   r   r   b   s   
r   c                   @  ó   e Zd ZdZdd„ ZdS )ÚConnectionszCollection of connection pools.c                 C  s   |j |d�S ©N©r-   )ÚPool©r   Ú
connectionr-   r   r   r   rD   k   r   zConnections.createN©r=   r>   r?   r@   rD   r   r   r   r   rK   h   ó    rK   rM   c                   @  rJ   )Ú	ProducerszCollection of producer pools.c                 C  s   t t| |d�S rL   )r
   r   rO   r   r   r   rD   u   s   zProducers.createNrQ   r   r   r   r   rS   r   rR   rS   c                   C  s   t dd„ tD ƒŽ S )Nc                 s  s$   � | ]}|r
|  ¡ ntg ƒV  qd S r   )ÚvaluesÚiter)Ú.0Úgr   r   r   Ú	<genexpr>}   s   €" z_all_pools.<locals>.<genexpr>)r   rH   r   r   r   r   Ú
_all_pools|   s   rY   c                   C  s   t d S )z"Get current connection pool limit.r   )Ú_limitr   r   r   r   r   €   s   r   Fc                 C  s>   | pd} t d p	d}| |kr| t d< tƒ D ]}| | ¡ q| S )zSet new connection pool limit.r   )rZ   rY   Úresize)r-   ÚforceÚreset_afterÚignore_errorsÚglimitÚpoolr   r   r   r   …   s   
r   c               	   O  s@   t ƒ D ]}z| ¡  W q ty   Y qw tD ]}| ¡  qdS )z*Reset all pools by closing open resources.N)rY   Úforce_close_allÚ	ExceptionrH   r   )r    r!   r`   r   r   r   r   r   �   s   
ÿ
ÿr   )FFF)$r@   Ú
__future__r   ÚosÚ	itertoolsr   rP   r   Ú	messagingr   Úutils.collectionsr   Úutils.compatr   Úutils.functionalr	   Ú__all__rZ   rH   ÚobjectrE   ÚenvironÚgetÚdisable_limit_protectionr   r
   r   r   rK   r   rS   r   rY   r   r   r   r   r   r   r   Ú<module>   s4    4
