Ë
    3ýj|  ã                  óv   — d Z ddlmZ ddl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
„ Z G d„ d«      Zy)z%Generic resource pool implementation.é    )ÚannotationsN)Únullcontext)ÚEmptyÚ	LifoQueueé   )Ú
exceptions)Úregister_after_fork)Úlazyc                óD   — 	 | j                  «        y # t        $ r Y y w xY w©N)Úforce_close_allÚ	Exception)Úresources    úH/root/telegram-saas/.venv/lib/python3.12/site-packages/kombu/resource.pyÚ_after_fork_cleanup_resourcer      s%   € ðØ× Ñ Õ"øÜò Ùðús   ‚ “	žc                  ó  — e Zd ZdZej
                  ZdZdd„Zd„ Zd„ Z	dd„Z
d„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zdd„Zdd„Zdd„Zed„ «       Zej,                  d„ «       Zej0                  j3                  d«      re
ZeZdZd„ Z
d„ Zyy)ÚResourcezPool of resources.FNc                ó6  — t        |t        «      rt        d«      ‚|| _        |xs d| _        d| _        |�|n| j                  | _        t        «       | _        t        «       | _
        | j                  rt        �t        | t        «       | j                  «        y )Núlimit must be an int, not boolr   F)Ú
isinstanceÚboolÚ	TypeErrorÚ_limitÚpreloadÚ_closedÚclose_after_forkr   Ú	_resourceÚsetÚ_dirtyr	   r   Úsetup)ÚselfÚlimitr   r   s       r   Ú__init__zResource.__init__   s†   € ä�eœTÔ"ÜÐ<Ó=Ð=ØˆŒØ’| !ˆŒØˆŒð  Ð+ñ Ø15×1FÑ1Fð 	Ôô
 #›ˆŒÜ“eˆŒØ× Ò Ô%8Ð%DÜ Ô&BÔCØ�
‰
�ó    c                ó   — t        d«      ‚)Nzsubclass responsibility)ÚNotImplementedError©r!   s    r   r    zResource.setup.   s   € Ü!Ð";Ó<Ð<r$   c                óè   — | j                   r=t        | j                  «      | j                   k\  r| j                  | j                   «      ‚| j                  j                  | j                  «       «       y r   )r"   Úlenr   ÚLimitExceededr   Ú
put_nowaitÚnewr'   s    r   Ú_add_when_emptyzResource._add_when_empty1   sL   € Ø�:Š:œ#˜dŸk™kÓ*¨d¯j©jÒ8Ø×$Ñ$ T§Z¡ZÓ0Ð0ð 	�‰×!Ñ! $§(¡(£*Õ-r$   c                ó  ‡ ‡— ‰ j                   rt        d«      ‚‰ j                  rM	 	 ‰ j                  j	                  ||¬«      Š	 ‰ j                  ‰«      Š‰ j                  j                  ‰«       n‰ j                  ‰ j                  «       «      Šˆˆ fd„}|‰_
        ‰S # t        $ r? t        ‰t        «      r‰ j                  j                  ‰«       ‚ ‰ j                  ‰«       ‚ w xY w# t        $ r ‰ j                  «        Y nw xY wŒå)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.
        zAcquire on closed pool)ÚblockÚtimeoutc                 ó(   •— ‰j                  ‰ «       y)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)Úrelease)ÚRr!   s   €€r   r2   z!Resource.acquire.<locals>.release_   s   ø€ ð �L‰L˜�Or$   )r   ÚRuntimeErrorr"   r   ÚgetÚprepareÚBaseExceptionr   r
   r+   r2   r   Úaddr   r-   r,   )r!   r/   r0   r2   r3   s   `   @r   ÚacquirezResource.acquire9   sñ   ù€ ð �<Š<ÜÐ7Ó8Ð8Ø�:Š:ØðØŸ™×*Ñ*°ÀÐ*ÓH�Að	Ø ŸL™L¨›O˜ð —K‘K—O‘O AÔ&Øà—‘˜TŸX™X›ZÓ(ˆAõ		ð ˆŒ	àˆøô3 )ò Ü% a¬Ô.à ŸN™N×5Ñ5°aÔ8ð ð !ŸL™L¨œOØðûô ò +Ø×(Ñ(Ö*ð+úð s   ¨C, ÁB! Â!AC)Ã,DÄDc                ó   — |S r   © ©r!   r   s     r   r6   zResource.preparem   s   € Øˆr$   c                ó$   — |j                  «        y r   )Úcloser<   s     r   Úclose_resourcezResource.close_resourcep   s   € Ø�‰Õr$   c                 ó   — y r   r;   r<   s     r   Úrelease_resourcezResource.release_resources   ó   € Ør$   c                ót   — | j                   r| j                  j                  |«       | j                  |«       y)zqReplace existing resource with a new instance.

        This can be used in case of defective resources.
        N)r"   r   Údiscardr?   r<   s     r   ÚreplacezResource.replacev   s+   € ð
 �:Š:Ø�K‰K×Ñ Ô)Ø×Ñ˜HÕ%r$   c                óÎ   — | j                   rH| j                  j                  |«       | j                  j	                  |«       | j                  |«       y | j                  |«       y r   )r"   r   rD   r   r+   rA   r?   r<   s     r   r2   zResource.release   sI   € Ø�:Š:Ø�K‰K×Ñ Ô)Ø�N‰N×%Ñ% hÔ/Ø×!Ñ! (Õ+à×Ñ Õ)r$   c                 ó   — y r   r;   r<   s     r   Úcollect_resourcezResource.collect_resource‡   rB   r$   c                ó~  — | j                   ry|| _         | j                  }| j                  }	 	 |j                  «       }	 | j                  |«       Œ$# t        $ r Y nw xY w# t        $ r Y Œw xY w	 	 |j                  j                  «       }n# t        $ r Y yw xY w	 | j                  |«       n# t        $ r Y nw xY wŒN)aa  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).

        Arguments:
        ---------
            close_pool (bool): If True (default) then the pool is marked
                as closed. In case of False the pool can be reused.
        N)	r   r   r   ÚpopÚKeyErrorrH   ÚAttributeErrorÚqueueÚ
IndexError)r!   Ú
close_poolÚdirtyr   ÚdresÚress         r   r   zResource.force_close_allŠ   sÏ   € ð �<Š<ØØ!ˆŒØ—‘ˆØ—>‘>ˆØðØ—y‘y“{�ðØ×%Ñ% dÔ+ð øô ò Ùðûô "ò ÙðúàðØ—n‘n×(Ñ(Ó*‘øÜò ÙðúðØ×%Ñ% cÕ*øÜ!ò Ùðúð sG   ¯A Á A! Á	AÁAÁ!	A-Á,A-Á2B Â	BÂBÂB/ Â/	B;Â:B;c                óœ  — t        |t        «      rt        d«      ‚| j                  }| j                  rCd|cxk  r| j                  k  r.n n+|s)|s%t        dj                  | j                  |«      «      ‚d}|| _        |r	 | j                  d¬«       | j                  «        ||k  r| j                  |dkD  ¬«       y y # t        $ r Y Œ7w xY w)Nr   r   z,Can't shrink pool when in use: was={} now={}TF)rO   )Úcollect)r   r   r   r   r   r4   Úformatr   r   r    Ú_shrink_down)r!   r"   ÚforceÚignore_errorsÚresetÚ
prev_limits         r   ÚresizezResource.resize­   sË   € ô �eœTÔ"ÜÐ<Ó=Ð=Ø—[‘[ˆ
Ø�KŠK˜A Ô3¨¯©Õ3¹]ÙÜ"ØB×IÑIØŸ™ Uó,ó-ð -ð ˆEØˆŒÙðØ×$Ñ$°Ð$Ô6ð 	�
‰
ŒØ�:ÒØ×Ñ e¨a¡iÐÕ0ð øô ò Ùðús   ÂB? Â?	CÃ
Cc                ó   — | j                   }t        |dt        «       «      5  t        |j                  «      r³t        |j                  «      t        | j
                  «      z   | j                  kD  r{|j                  j                  «       }|r| j                  |«       t        |j                  «      r9t        |j                  «      t        | j
                  «      z   | j                  kD  rŒ{d d d «       y # 1 sw Y   y xY w)NÚmutex)	r   Úgetattrr   r)   rM   r   r"   rJ   rH   )r!   rT   r   r3   s       r   rV   zResource._shrink_downÃ   s·   € Ø—>‘>ˆô �X˜w¬«Ó6ñ 	-ä�h—n‘nÔ%¬3¨x¯~©~Ó+>ÄÀTÇ[Á[ÓAQÑ+QÐUY×U_ÑU_Ò*_Ø—N‘N×&Ñ&Ó(�ÙØ×)Ñ)¨!Ô,ô �h—n‘nÔ%¬3¨x¯~©~Ó+>ÄÀTÇ[Á[ÓAQÑ+QÐUY×U_ÑU_Ó*_÷	-÷ 	-ñ 	-ús   ¢CC4Ã4C=c                ó   — | j                   S r   )r   r'   s    r   r"   zResource.limitÎ   s   € à�{‰{Ðr$   c                ó&   — | j                  |«       y r   )r[   )r!   r"   s     r   r"   zResource.limitÒ   s   € à�‰�EÕr$   ÚKOMBU_DEBUG_POOLr   c                óx  — dd l }| j                  dz   x}| _        t        d|› d| j                  j                  › �«        | j
                  |i |¤Ž}||_        t        d|› d| j                  j                  › �«       t        |d«      sg |_        |j                  j                  |j                  «       «       |S )Nr   r   ú+z	 ACQUIRE ú-Úacquired_by)Ú	tracebackÚ_next_resource_idÚprintÚ	__class__Ú__name__Ú_orig_acquireÚ_resource_idÚhasattrre   ÚappendÚformat_stack)r!   ÚargsÚkwargsrf   ÚidÚrs         r   r9   zResource.acquireÜ   s¬   € ÛØ*.×*@Ñ*@À1Ñ*DÐDˆB�Ô'Ü�A�b�T˜ 4§>¡>×#:Ñ#:Ð";Ð<Ô=Ø"�×"Ñ" DÐ3¨FÑ3ˆAØˆAŒNÜ�A�b�T˜ 4§>¡>×#:Ñ#:Ð";Ð<Ô=Ü˜1˜mÔ,Ø "�”Ø�M‰M× Ñ  ×!7Ñ!7Ó!9Ô:ØˆHr$   c                óþ   — |j                   }t        d|› d| j                  j                  › �«       | j	                  |«      }t        d|› d| j                  j                  › �«       | xj
                  dz  c_        |S )Nrc   z	 RELEASE rd   r   )rl   rh   ri   rj   Ú_orig_releaserg   )r!   r   rr   rs   s       r   r2   zResource.releaseè   ss   € Ø×&Ñ&ˆBÜ�A�b�T˜ 4§>¡>×#:Ñ#:Ð";Ð<Ô=Ø×"Ñ" 8Ó,ˆAÜ�A�b�T˜ 4§>¡>×#:Ñ#:Ð";Ð<Ô=Ø×"Ò" aÑ'Õ"ØˆHr$   )NNN)FN)T)FFF)rj   Ú
__module__Ú__qualname__Ú__doc__r   r*   r   r#   r    r-   r9   r6   r?   rA   rE   r2   rH   r   r[   rV   Úpropertyr"   ÚsetterÚosÚenvironr5   rk   ru   rg   r;   r$   r   r   r      s·   „ Ùà×,Ñ,€MàÐóò$=ò.ó2òhòòò&ò*òó!óF1ó,	-ð ñó ðð ‡\�\ñó ðð 
‡z�z‡~�~Ð(Ô)ØˆØˆàÐò
	ó	ð% *r$   r   )rx   Ú
__future__r   r{   Ú
contextlibr   rM   r   r   Ú r   Úutils.compatr	   Úutils.functionalr
   r   r   r;   r$   r   ú<module>r‚      s.   ðÙ +å "ã 	Ý "ß "å Ý -Ý "ò÷Yò Yr$   