o
    wvXjø  ã                   @   s&  d Z ddlmZmZ ddlZddlmZ ddlmZ ddl	m
Z
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.é    )Úabsolute_importÚunicode_literalsN)Úchainé   )ÚResource)ÚrangeÚvalues)Ú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   úH/var/www/html/myproject/venv/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                    s4   || _ | dd ¡p| j| _tt| ƒj|i |¤Ž d S )Nr	   )r   Úpopr	   Úsuperr   Ú__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   Únew1   s   
zProducerPool.newc                 C   s.   | j rt| j ƒD ]}| j |  ¡ ¡ qd S d S r   )Úlimitr   Ú	_resourceÚ
put_nowaitr/   )r"   Ú_r   r   r   Úsetup4   s
   þzProducerPool.setupc                 C   s   d S r   r   ©r"   Úresourcer   r   r   Úclose_resource9   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t| ƒ |¡ d S r   )Ú__connection__r,   Úchannelr    r   r5   r%   r   r   r,   H   s   
zProducerPool.release)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   Úclose_after_forkr!   r*   r.   r/   r4   r7   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   )r0   rC   r   r   )r"   r0   rC   r   r   r   r!   R   s
   ÿzPoolGroup.__init__c                 C   s   t dƒ‚)Nz!PoolGroups must define ``create``)ÚNotImplementedError)r"   r6   r0   r   r   r   ÚcreateX   s   zPoolGroup.createc                 C   s,   | j }|tu r
tƒ }|  ||¡ }| |< |S r   )r0   Úuse_global_limitr   rF   )r"   r6   r0   Úkr   r   r   Ú__missing__[   s
   zPoolGroup.__missing__)NT)r?   r@   rA   rB   r!   rF   rI   r   r   r   r   r   O   s
    
r   c                 C   s   t  | ¡ | S )z*Register group (can be used as decorator).)Ú_groupsÚappendr   r   r   r   r   c   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©r0   )ÚPool©r"   Ú
connectionr0   r   r   r   rF   l   r   zConnections.createN©r?   r@   rA   rB   rF   r   r   r   r   rM   i   ó    rM   rO   c                   @   rL   )Ú	ProducerszCollection of producer pools.c                 C   s   t t| |d�S rN   )r   r   rQ   r   r   r   rF   t   s   zProducers.createNrS   r   r   r   r   rU   q   rT   rU   c                   C   s   t dd„ tD ƒŽ S )Nc                 S   s    g | ]}|r
t |ƒntg ƒ‘qS r   )r   Úiter)Ú.0Úgr   r   r   Ú
<listcomp>z   s     z_all_pools.<locals>.<listcomp>)r   rJ   r   r   r   r   Ú
_all_poolsy   s   rZ   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   )r[   rZ   Úresize)r0   Ú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)rZ   Úforce_close_allÚ	ExceptionrJ   r   )r#   r$   ra   r   r   r   r   r   �   s   
ÿ
ÿr   )FFF)(rB   Ú
__future__r   r   ÚosÚ	itertoolsr   rR   r   Úfiver   r   Ú	messagingr	   Úutils.collectionsr
   Úutils.compatr   Úutils.functionalr   Ú__all__r[   rJ   ÚobjectrG   ÚenvironÚgetÚdisable_limit_protectionr   r   r   r   rM   r   rU   r   rZ   r   r   r   r   r   r   r   Ú<module>   s6    4
