
    Ih                    p   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*                  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#y)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                $    | j                          y N)cleargroups    D/var/www/html/planif/env/lib/python3.12/site-packages/kombu/pools.py_after_fork_cleanup_groupr      s    	KKM    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                |    || _         |j                  dd       xs | j                  | _        t        |   |i | y )Nr   )r   popr   super__init__)selfr   argskwargs	__class__s       r   r!   zProducerPool.__init__    s8    &

:t4E$)&)r   c                :    | j                   j                  d      S )NT)block)r   acquirer"   s    r   _acquire_connectionz ProducerPool._acquire_connection%   s    ''d'33r   c                    | j                         }	 | j                  |      S # t        $ r |j                           w xY wr   )r*   r   BaseExceptionrelease)r"   conns     r   create_producerzProducerPool.create_producer(   s?    '')	==&& 	LLN	s   # >c                ,    t        | j                        S r   )r
   r/   r)   s    r   newzProducerPool.new0   s    D(())r   c                    | j                   rDt        | j                         D ]+  }| j                  j                  | j	                                - y y r   )limitrange	_resource
put_nowaitr1   )r"   _s     r   setupzProducerPool.setup3   s>    ::4::& 6))$((*56 r   c                     y r    )r"   resources     r   close_resourcezProducerPool.close_resource8   s    r   c                    t        |      r |       }|j                  $| j                         }	 |j                  |       |S |S # t        $ r |j                           w xY wr   )callable_channelr*   reviver,   r-   )r"   pr.   s      r   preparezProducerPool.prepare;   s`    A;A::++-D q ! s   A A c                ~    |j                   r|j                   j                          d |_        t        |   |       y r   )__connection__r-   channelr    )r"   r;   r%   s     r   r-   zProducerPool.releaseG   s2    ""##++-!r   )__name__
__module____qualname____doc__r   close_after_forkr!   r*   r/   r1   r8   r<   rB   r-   __classcell__)r%   s   @r   r   r      s>    4H*
4*6

" "r   r   c                  $    e Zd ZdZddZd Zd Zy)r   zCollection of resource pools.Nc                h    || _         || _        | j                  rt        t        | t               y y y r   )r3   rJ   r	   r   )r"   r3   rJ   s      r   r!   zPoolGroup.__init__Q   s4    
 0  %8%D&?@ &E r   c                    t        d      )Nz!PoolGroups must define ``create``)NotImplementedError)r"   r;   r3   s      r   createzPoolGroup.createW   s    !"EFFr   c                p    | j                   }|t        u r
t               }| j                  ||      x}| |<   |S r   )r3   use_global_limitr   rP   )r"   r;   r3   ks       r   __missing__zPoolGroup.__missing__Z   s9    

$$KE![[599DNr   )NT)rF   rG   rH   rI   r!   rP   rT   r:   r   r   r   r   N   s    'AGr   r   c                0    t         j                  |        | 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y)ConnectionszCollection of connection pools.c                &    |j                  |      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y)	ProducerszCollection of producer pools.c                *    t        t        |   |      S r[   )r   r   r^   s      r   rP   zProducers.createu   s    K
35AAr   Nr`   r:   r   r   rb   rb   r   s    'Br   rb   c                 (    t        d t        D         S )Nc              3  V   K   | ]!  }|r|j                         n
t        g        # y wr   )valuesiter).0gs     r   	<genexpr>z_all_pools.<locals>.<genexpr>}   s!     Dq!AHHJb1Ds   '))r   rV   r:   r   r   
_all_poolsrk   |   s    DGDEEr   c                     t         d   S )z"Get current connection pool limit.r   )_limitr:   r   r   r   r      s    !9r   c                    | xs d} t         d   xs d}| |k7  r)| t         d<   t               D ]  }|j                  |         | S )zSet new connection pool limit.r   )rm   rk   resize)r3   forcereset_afterignore_errorsglimitpools         r   r   r      sJ    JQEAY^!Fq	L 	DKK	Lr   c                     t               D ]  }	 |j                           t        D ]  }|j	                           y# t        $ r Y =w xY w)z*Reset all pools by closing open resources.N)rk   force_close_all	ExceptionrV   r   )r#   r$   rt   r   s       r   r   r      sR     	  "
    		s   =	A	A	)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

8 ::>>*JK 1"8 1"h (,) , [/?@AB	 B 9+;<=	F
r   