Ë
    UV.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    úPC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\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                ó   — || _         |xs d| _        d| _        |�|n| j                  | _        t	        «       | _        t        «       | _        | j                  rt        �t        | t        «       | j                  «        y )Nr   F)Ú_limitÚpreloadÚ_closedÚclose_after_forkr   Ú	_resourceÚsetÚ_dirtyr	   r   Úsetup)ÚselfÚlimitr   r   s       r   Ú__init__zResource.__init__   sp   € ØˆŒØ’| !ˆŒØˆŒð  Ð+ñ Ø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_empty.   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   r.   z!Resource.acquire.<locals>.release\   s   ø€ ð �L‰L˜�Or    )r   ÚRuntimeErrorr   r   ÚgetÚprepareÚBaseExceptionÚ
isinstancer
   r'   r.   r   Úaddr   r)   r(   )r   r+   r,   r.   r/   s   `   @r   ÚacquirezResource.acquire6   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   r2   zResource.preparej   s   € Øˆr    c                ó$   — |j                  «        y r   )Úcloser9   s     r   Úclose_resourcezResource.close_resourcem   s   € Ø�‰Õr    c                 ó   — y r   r8   r9   s     r   Úrelease_resourcezResource.release_resourcep   ó   € Ø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<   r9   s     r   ÚreplacezResource.replaces   s+   € ð
 �:Š:Ø�K‰K×Ñ Ô)Ø×Ñ˜HÕ%r    c                óÎ   — | j                   rH| j                  j                  |«       | j                  j	                  |«       | j                  |«       y | j                  |«       y r   )r   r   rA   r   r'   r>   r<   r9   s     r   r.   zResource.release|   sI   € Ø�:Š:Ø�K‰K×Ñ Ô)Ø�N‰N×%Ñ% hÔ/Ø×!Ñ! (Õ+à×Ñ Õ)r    c                 ó   — y r   r8   r9   s     r   Úcollect_resourcezResource.collect_resource„   r?   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ÚKeyErrorrE   Ú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                óf  — | 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   z,Can't shrink pool when in use: was={} now={}TF)rL   )Úcollect)r   r   r0   Úformatr   r   r   Ú_shrink_down)r   r   ÚforceÚignore_errorsÚresetÚ
prev_limits         r   ÚresizezResource.resizeª   s³   € Ø—[‘[ˆ
Ø�KŠK˜A Ô3¨¯©Õ3¹]ÙÜ"ØB×IÑIØŸ™ Uó,ó-ð -ð ˆEØˆŒÙðØ×$Ñ$°Ð$Ô6ð 	�
‰
ŒØ�:ÒØ×Ñ e¨a¡iÐÕ0ð øô ò Ùðús   Á&B$ Â$	B0Â/B0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%   rJ   r   r   rG   rE   )r   rQ   r   r/   s       r   rS   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_Ó*_÷ 7×6Ñ6ús   ¢CC4Ã4C=c                ó   — | j                   S r   )r   r#   s    r   r   zResource.limitÇ   s   € à�{‰{Ðr    c                ó&   — | j                  |«       y r   )rX   )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Úhasattrrb   ÚappendÚformat_stack)r   ÚargsÚkwargsrc   ÚidÚrs         r   r6   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 )Nr`   z	 RELEASE ra   r   )ri   re   rf   rg   Ú_orig_releaserd   )r   r   ro   rp   s       r   r.   zResource.releaseá   ss   € Ø×&Ñ&ˆBÜ�A�b�T˜ 4§>¡>×#:Ñ#:Ð";Ð<Ô=Ø×"Ñ" 8Ó,ˆAÜ�A�b�T˜ 4§>¡>×#:Ñ#:Ð";Ð<Ô=Ø×"Ò" aÑ'Õ"ØˆHr    )NNN)FN)T)FFF)rg   Ú
__module__Ú__qualname__Ú__doc__r   r&   r   r   r   r)   r6   r2   r<   r>   rB   r.   rE   r   rX   rS   Úpropertyr   ÚsetterÚosÚenvironr1   rh   rr   rd   r8   r    r   r   r      s·   „ Ùà×,Ñ,€MàÐóò=ò.ó2òhòòò&ò*òó!óF1ó$	-ð ñó ðð ‡\�\ñó ðð 
‡z�z‡~�~Ð(Ô)ØˆØˆàÐò
	ó	ð% *r    r   )ru   Ú
__future__r   rx   Ú
contextlibr   rJ   r   r   Ú r   Úutils.compatr	   Úutils.functionalr
   r   r   r8   r    r   Ú<module>r      s.   ðÙ +å "ã 	Ý "ß "å Ý -Ý "ò÷Rò Rr    