
    ^f                       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 Z G d de          Z G d de          Zd Z G d de          Z e ee                    Z G d de          Z e ee                    Zd Z d Z!ddZ"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                .    |                                   d S N)cleargroups    =/var/www/html/env/lib/python3.11/site-packages/kombu/pools.py_after_fork_cleanup_groupr      s    	KKMMMMM    c                  X     e Zd ZdZeZdZ fdZd Zd Zd Z	d Z
d Zd	 Z fd
Z xZS )r   z*Pool of :class:`kombu.Producer` instances.Tc                    || _         |                    dd           p| j        | _         t                      j        |i | d S )Nr   )r   popr   super__init__)selfr   argskwargs	__class__s       r   r!   zProducerPool.__init__    sI    &

:t44E$)&)))))r   c                8    | j                             d          S )NT)block)r   acquirer"   s    r   _acquire_connectionz ProducerPool._acquire_connection%   s    ''d'333r   c                    |                                  }	 |                     |          S # t          $ r |                                  w xY wr   )r*   r   BaseExceptionrelease)r"   conns     r   create_producerzProducerPool.create_producer(   sU    ''))	==&&& 	 	 	LLNNN	s	   +  Ac                *    t          | j                  S r   )r
   r/   r)   s    r   newzProducerPool.new0   s    D()))r   c                    | j         rCt          | j                   D ]0}| j                            |                                            /d S d S r   )limitrange	_resource
put_nowaitr1   )r"   _s     r   setupzProducerPool.setup3   sZ    : 	64:&& 6 6))$((**5555	6 	66 6r   c                    d S r    )r"   resources     r   close_resourcezProducerPool.close_resource8   s    r   c                    t          |          r
 |            }|j        N|                                 }	 |                    |           n## t          $ r |                                  w xY w|S r   )callable_channelr*   reviver,   r-   )r"   pr.   s      r   preparezProducerPool.prepare;   s|    A;; 	A:++--D     s   A  A,c                    |j         r|j                                          d |_        t                                          |           d S r   )__connection__r-   channelr    )r"   r;   r%   s     r   r-   zProducerPool.releaseG   sG    " 	.#++---!!!!!r   )__name__
__module____qualname____doc__r   close_after_forkr!   r*   r/   r1   r8   r<   rB   r-   __classcell__)r%   s   @r   r   r      s        44H* * * * *
4 4 4  * * *6 6 6
  
 
 
" " " " " " " " "r   r   c                  &    e Zd ZdZddZd Zd ZdS )r   zCollection of resource pools.NTc                p    || _         || _        | j        rt          t          | t                     d S d S d S r   )r3   rJ   r	   r   )r"   r3   rJ   s      r   r!   zPoolGroup.__init__Q   sL    
 0  	A%8%D&?@@@@@	A 	A%D%Dr   c                     t          d          )Nz!PoolGroups must define ``create``)NotImplementedError)r"   r;   r3   s      r   createzPoolGroup.createW   s    !"EFFFr   c                x    | j         }|t          u rt                      }|                     ||          x}| |<   |S r   )r3   use_global_limitr   rP   )r"   r;   r3   ks       r   __missing__zPoolGroup.__missing__Z   s?    
$$$KKE![[5999DNr   )NT)rF   rG   rH   rI   r!   rP   rT   r:   r   r   r   r   N   sS        ''A A A AG G G    r   r   c                :    t                               |            | S )z*Register group (can be used as decorator).)_groupsappendr   s    r   r   r   b   s    NN5Lr   c                      e Zd ZdZd ZdS )ConnectionszCollection of connection pools.c                .    |                     |          S Nr3   )Poolr"   
connectionr3   s      r   rP   zConnections.createk   s    U+++r   NrF   rG   rH   rI   rP   r:   r   r   rY   rY   h   s)        )), , , , ,r   rY   r\   c                      e Zd ZdZd ZdS )	ProducerszCollection of producer pools.c                :    t          t          |         |          S r[   )r   r   r^   s      r   rP   zProducers.createu   s    K
35AAAAr   Nr`   r:   r   r   rb   rb   r   s.        ''B B B B Br   rb   c                 2    t          d t          D              S )Nc              3  `   K   | ])}|r|                                 nt          g           V  *d S r   )valuesiter).0gs     r   	<genexpr>z_all_pools.<locals>.<genexpr>}   s9      DDq!1AHHJJJbDDDDDDr   )r   rV   r:   r   r   
_all_poolsrk   |   s    DDGDDDEEr   c                     t           d         S )z"Get current connection pool limit.r   )_limitr:   r   r   r   r      s    !9r   Fc                    | pd} t           d         pd}| |k    r0| t           d<   t                      D ]}|                    |            | S )zSet new connection pool limit.r   )rm   rk   resize)r3   forcereset_afterignore_errorsglimitpools         r   r   r      sW    JQEAY^!Fq	LL 	 	DKKLr   c                     t                      D ]'}	 |                                 # t          $ r Y $w xY wt          D ]}|                                 dS )z*Reset all pools by closing open resources.N)rk   force_close_all	ExceptionrV   r   )r#   r$   rt   r   s       r   r   r      sw      	  """" 	 	 	D	   s   '
44)FFF)$rI   
__future__r   os	itertoolsr   r_   r   	messagingr   utils.collectionsr   utils.compatr	   utils.functionalr
   __all__rm   rV   objectrR   environgetdisable_limit_protectionr   r   r   r   rY   r   rb   r   rk   r   r   r   r:   r   r   <module>r      s"     " " " " " " 				                         + + + + + + - - - - - - " " " " " "J

688 :>>*JKK   1" 1" 1" 1" 1"8 1" 1" 1"h       (  , , , , ,) , , , n[[/?@@@AAB B B B B	 B B B N99+;<<<==	F F F  
       r   