Ë
    §Œjy&  ã            
       ó¸   — d 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	giZg d
¢Z G d„ d«      Zedd„«       Zd„ Zd„ Zddddedddddœ	d„Zd„ Zd„ Zddœd„Zy)z,
Thin wrappers around `concurrent.futures`.
é    N)Úcontextmanager©Úlength_hinté   )Útqdm)ÚTqdmWarningzgithub.com/Ú	casperdcl)Ú
thread_mapÚprocess_mapÚinterpreter_mapc                   óH   — e Zd ZdZddlmZ ddlmZ d„ Z	dd„Z
d„ Zd„ Zd	„ Zy
)Ú_InterpreterLockz3Reentrant lock backed by a cross-interpreter queue.r   )Ú	get_ident)Ú	monotonicc                 óR   — ddl m} || _         |«       | _        d | _        d| _        y )Nr   )ÚRLock)Ú	threadingr   Ú_queueÚ_lockÚ_ownerÚ_depth)ÚselfÚqueuer   s      úa/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/tqdm/contrib/concurrent.pyÚ__init__z_InterpreterLock.__init__   s#   € Ý#ØˆŒÙ“WˆŒ
ØˆŒØˆ�ó    c                 ój  — ddl m} | j                  «       }|dk(  r| j                  j	                  |«      }n| j                  j	                  ||«      }|sy| j
                  r| xj
                  dz  c_        y	 |s| j                  j                  «        n\|dk(  r| j                  j                  «        n<t        d|| j                  «       |z
  z
  «      }| j                  j                  |¬«       | j                  «       | _        d| _        y# |$ r | j                  j                  «        Y yw xY w)Nr   )ÚEmptyéÿÿÿÿFé   T)Útimeout)r   r   Ú_timer   Úacquirer   r   Ú
get_nowaitÚgetÚmaxÚreleaser   r   )r   Úblockingr!   r   ÚstartÚacquiredÚ	remainings          r   r#   z_InterpreterLock.acquire   sø   € ÝØ—
‘
“ˆØ�bŠ=Ø—z‘z×)Ñ)¨(Ó3‰Hà—z‘z×)Ñ)¨(°GÓ<ˆHÙØØ�;Š;Ø�KŠK˜1Ñ�KØð
	ÙØ—‘×&Ñ&Õ(Ø˜B’Ø—‘—‘Õ!ä  7¨d¯j©j«l¸UÑ.BÑ#CÓD�	Ø—‘—‘¨	�Ô2ð —n‘nÓ&ˆŒØˆŒØøð ò 	Ø�J‰J×ÑÔ Ùð	ús   Á:A9D ÄD2Ä1D2c                 ó  — | j                   | j                  «       k7  rt        d«      ‚| xj                  dz  c_        | j                  s"d | _         | j                  j                  d «       | j                  j                  «        y )Nzcannot release un-acquired lockr    )r   r   ÚRuntimeErrorr   r   Úputr   r'   ©r   s    r   r'   z_InterpreterLock.release6   s]   € Ø�;‰;˜$Ÿ.™.Ó*Ò*ÜÐ@ÓAÐAØ�Š�qÑ�Ø�{Š{ØˆDŒKØ�K‰K�O‰O˜DÔ!Ø�
‰
×ÑÕr   c                 ó&   — | j                  «        | S ©N)r#   r/   s    r   Ú	__enter__z_InterpreterLock.__enter__?   s   € Ø�‰ŒØˆr   c                 ó$   — | j                  «        y r1   )r'   )r   Úexcs     r   Ú__exit__z_InterpreterLock.__exit__C   s   € Ø�‰�r   N)Tr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Útimer   r"   r   r#   r'   r2   r5   © r   r   r   r      s$   „ Ù=Ý#Ý'òóò6òór   r   Ú c              #   óÂ   K  — t        | dd«      }|€|xs | j                  «       }t        |||«      }| j                  |«       |–— |€| `y| j                  |«       y­w)z>get (create if necessary) and then restore `tqdm_class`'s lockr   N)ÚgetattrÚget_lockÚset_lockr   )Ú
tqdm_classÚ	lock_nameÚlockÚold_locks       r   Úensure_lockrE   G   si   è ø€ ô �z 7¨DÓ1€HØ€|ØÒ0˜:×.Ñ.Ó0ˆÜ�4˜ DÓ)€DØ×Ñ˜ÔØ
‚JØÐØÑà×Ñ˜HÕ%ùs   ‚AAc           	      ó”   — dt         j                  ›d| j                  ›d| j                  j	                  d«      ›d|›d�	}t
        |ffS )zGReturn an initializer which bootstraps the parent import path and lock.zimport sys
sys.path[:] = z™
from concurrent import interpreters
from importlib import import_module
from tqdm.contrib.concurrent import _InterpreterLock
tqdm_class = import_module(z)
for name in Ú.z…:
    tqdm_class = getattr(tqdm_class, name)
tqdm_class.monitor_interval = 0
tqdm_class.set_lock(_InterpreterLock(interpreters.Queue(z))))ÚsysÚpathr7   r8   ÚsplitÚexec)rA   Úlock_queue_idÚcodes      r   Ú_get_interpreter_initrN   V   sk   € ð	ÜŸ™˜ð %&ð '1×&;Ñ&;Ð%>ð ?Ø!×.Ñ.×4Ñ4°SÓ9Ð<ð =Cð DQÐBSÐSVð		Xð 	ô �$�ˆ=Ðr   c                 ó,   ‡— t        ˆfd„| D «       «      S )z min(map(length_hint, iterables))c              3   óF   •K  — | ]  }t        |d «      xŠdk\  sŒ‰–— Œ y­w)r   r   Nr   )Ú.0ÚitÚns     €r   Ú	<genexpr>z_min_map_len.<locals>.<genexpr>h   s%   øè ø€ ÐH™9�R¬k¸"¸bÓ.AÐ)A¨ÀaÓ(GŒq™9ùs   ƒ!š!)Úmin)Ú	iterablesrS   s    @r   Ú_min_map_lenrW   f   s   ø€ äÓH™9ÓHÓHÐHr   r    g        )	Úmax_workersr!   Ú	chunksizerB   rA   Ú	smoothingr   Ú_initializerÚ	_initargsc       	         ó  ‡‡— |j                  «       }d|vrt        |«      |d<   i }d|v r|j                  d«      |d<   i }dD ]  }||v sŒ|j                  |«      ||<   Œ d}|d   r6d|vr2	 ddlm} |xs t        d	 |«       xs d
dz   «      }|d   |kD  r||d<   d}t        |||¬«      5 }|	€|j                  }	|f}
 | d||	|
dœ|¤Ž5 } |dd|i|¤Ž5 Š|�d‰_
        |j                  Šˆˆfd„}||_        t         |j                  |g|¢­||dœ|¤Ž«      cddd«       cddd«       cddd«       S # t
        $ r	 ddlm} Y ŒÓw xY w# 1 sw Y   nxY w	 ddd«       n# 1 sw Y   nxY wddd«       y# 1 sw Y   yxY w)a  
    Implementation of `thread_map`, `process_map` and `interpreter_map`.

    Parameters
    ----------
    max_workers  : int
    timeout  : int
    buffersize  : int
        Requires Python>=3.14.
    thread_name_prefix  : str
    max_tasks_per_child  : int
    mp_context  : str
    ÚtotalÚ
buffersize)Úthread_name_prefixÚmax_tasks_per_childÚ
mp_contextNÚminitersr   )Úprocess_cpu_count)Ú	cpu_counté    r    é   T)rB   rC   )rX   ÚinitializerÚinitargsrZ   c                  ó@   •—  ‰| i |¤Ž}|j                  ˆfd„«       |S )Nc                 ó$   •— ‰j                  «       S r1   )Úupdate)Ú_Úpbars    €r   Ú<lambda>z4_executor_map.<locals>.patchsubmit.<locals>.<lambda>    s   ø€ °D·K±K´Mr   )Úadd_done_callback)ÚargsÚkwargsÚfutÚ	orisubmitrn   s      €€r   Úpatchsubmitz"_executor_map.<locals>.patchsubmitž   s&   ø€ Ù# TÐ4¨VÑ4�CØ×)Ñ)Ó*AÔBØ�Jr   )r!   rY   r;   )ÚcopyrW   ÚpopÚosrd   ÚImportErrorre   rU   rE   r@   Údynamic_minitersÚsubmitÚlistÚmap)ÚPoolExecutorÚfnrX   r!   rY   rB   rA   rZ   r   r[   r\   rV   Útqdm_kwargsrr   Ú
map_kwargsÚpool_kwargsÚkrz   re   Ú	rough_maxÚlkÚexru   rt   rn   s                          @@r   Ú_executor_mapr‡   k   sÕ  ù€ ð$ ×ÑÓ€FØ�fÑÜ& yÓ1ˆˆw‰Ø€JØ�vÑØ#)§:¡:¨lÓ#;ˆ
�<Ñ Ø€KÛHˆØ�Š;Ø#ŸZ™Z¨›]ˆK˜ŠNð Ið ÐØˆg‚˜:¨VÑ3ð	%Ý9ð  ÒB¤3 r©I«KÒ,<¸1ÀÑ+AÓ#Bˆ	Ø�'‰?˜YÒ&Ø!*ˆF�:ÑØ#ÐÜ	�Z¨9¸5Õ	AÀRàÐØ%×.Ñ.ˆLØ˜ˆIÙð ) k¸|ÐV_ñ )Ø'ò)Ø,.ÙÑ: iÐ:°6Ò:¸dØ#Ð/Ø,0�DÔ)ØŸI™I�	õð (�”	Ü˜F˜BŸF™FØðXØ"ñXØ,3¸yñXØLVñXó Y÷ ;Ð:÷)ð )÷ 
BÑ	Aøô ò 	%ß$ð	%ú÷ ;Ð:úÐ:÷)÷ )ñ )ú÷ 
B×	AÑ	AúsU   Á-D5 Â,E5Ã
E ÃAE
Ä	E Ä"	E5Ä5EÅEÅ
EÅE Å	E5Å E)	Å%E5Å5E>c                 ó.   — ddl m} t        || g|¢­i |¤ŽS )a°  
    Equivalent of `list(map(fn, *iterables))`
    driven by `concurrent.futures.ThreadPoolExecutor`.

    Parameters
    ----------
    max_workers  : int, optional
        Maximum number of workers to spawn; passed to `concurrent.futures.ThreadPoolExecutor`.
    thread_name_prefix  : str, optional
        Passed to `concurrent.futures.ThreadPoolExecutor` [default: ''].
    timeout  : int or float, optional
        Seconds to wait before raising `TimeoutError` if `__next__` is called and the
        result isn't available. [default: None].
    buffersize  : int, optional
        Requires Python>=3.14 [default: None].
    tqdm_class  : optional
        `tqdm` class to use for bars [default: tqdm.auto.tqdm].
    smoothing  : float, optional
        Passed to `tqdm_class`; the [default: 0] is average (due to erratic update frequency).
    lock_name  : str, optional
        Member of `tqdm_class.get_lock()` to use [default: ''].
    r   )ÚThreadPoolExecutor)Úconcurrent.futuresr‰   r‡   )r   rV   r€   r‰   s       r   r
   r
   §   s   € õ. 6ÜÐ+¨RÐK°)ÒK¸{ÑKÐKr   c                 óô   — ddl m} ddlm} |j	                  «       }|j                  d«       |j                  dt        «      }t        ||j                  «      \  }}t        || g|¢­t        |«      ||dœ|¤ŽS )aj  
    Equivalent of `list(map(fn, *iterables))`
    driven by `concurrent.futures.InterpreterPoolExecutor` (Python 3.14+).

    Parameters
    ----------
    Same as `thread_map`.

    Notes
    -----
    `fn`, its arguments, and its return values must be pickleable.
    Worker progress bars using the same `tqdm_class` share a cross-interpreter write lock.
    r   )Úinterpreters)ÚInterpreterPoolExecutorNrA   )r   r[   r\   )Ú
concurrentrŒ   rŠ   r�   Úcreate_queuer.   r%   Ú	tqdm_autorN   Úidr‡   r   )	r   rV   r€   rŒ   r�   Ú
lock_queuerA   rh   ri   s	            r   r   r   Â   s‚   € õ (Ý:Ø×*Ñ*Ó,€JØ‡N�N�4ÔØ—‘ ¬yÓ9€JÜ1°*¸j¿m¹mÓLÑ€K�ÜØ ðEØ&/ñEÜ7GÈ
Ó7SØ ¨HñEà8CñEð Er   Úmp_lock)rB   c                óŽ   — ddl m} |r,d|vr(t        |«      }|dkD  rddlm}  |d|z  t
        d¬«       t        || g|¢­d	|i|¤ŽS )
aI  
    Equivalent of `list(map(fn, *iterables))`
    driven by `concurrent.futures.ProcessPoolExecutor`.

    Parameters
    ----------
    max_workers  : int, optional
        Maximum number of workers to spawn; passed to `concurrent.futures.ProcessPoolExecutor`.
    timeout  : int or float, optional
        Seconds to wait before raising `TimeoutError` if `__next__` is called and the
        result isn't available. [default: None].
    chunksize  : int, optional
        Approximate size of chunks sent to worker processes; passed to
        `concurrent.futures.ProcessPoolExecutor.map`. [default: 1].
    buffersize  : int, optional
        Requires Python>=3.14 [default: None].
    max_tasks_per_child  : int, optional
        Maximum number of tasks a worker process can complete before being replaced
        with a new process; passed to `concurrent.futures.ProcessPoolExecutor`.
    mp_context  : multiprocessing.BaseContext, optional
        Multiprocessing context to use, e.g. `multiprocessing.get_context('fork')`.
    lock_name  : str, optional
        Member of `tqdm_class.get_lock()` to use [default: mp_lock].
    tqdm_class  : optional
        `tqdm` class to use for bars [default: tqdm.auto.tqdm].
    smoothing  : float, optional
        Passed to `tqdm_class`; the [default: 0] is average (due to erratic update frequency).
    r   )ÚProcessPoolExecutorrY   iè  )Úwarnz…Iterable length %d > 1000 but `chunksize` is not set. This may seriously degrade multiprocess performance. Set `chunksize=1` or more.r   )Ú
stacklevelrB   )rŠ   r•   rW   Úwarningsr–   r   r‡   )r   rB   rV   r€   r•   Úshortest_iterable_lenr–   s          r   r   r   Û   sf   € õ: 7Ù�[¨Ñ3ô !-¨YÓ 7ÐØ  4Ò'Ý%Ùð /à1FñGô ¨õ,ô Ð,¨bÐa°9ÒaÈ	ÐaÐU`ÑaÐar   )r<   N)r9   rH   Ú
contextlibr   Úoperatorr   Úautor   r�   Ústdr   Ú
__author__Ú__all__r   rE   rN   rW   r‡   r
   r   r   r;   r   r   Ú<module>r       sŒ   ðñó Ý %Ý  å $Ý à˜k˜]Ð+€
Ú
:€÷5ñ 5ðp ò&ó ð&òò Ið /3¸DÈAÐY[Ø C¨tÀ$ÐRVô9YòxLò6Eð2 +4õ (br   