o
    Ð­j’  ã                   @   s|   d 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	giZd
dgZeddd„ƒZdd„ Zdd
„ Zdd„ ZdS )z,
Thin wrappers around `concurrent.futures`.
é    )Úcontextmanager)Úlength_hint)Ú	cpu_counté   )Útqdm)ÚTqdmWarningzgithub.com/Ú	casperdclÚ
thread_mapÚprocess_mapÚ c                 c   sT   � t | ddƒ}|p|  ¡ }t |||ƒ}|  |¡ |V  |du r#| `dS |  |¡ dS )z>get (create if necessary) and then restore `tqdm_class`'s lockÚ_lockN)ÚgetattrÚget_lockÚset_lockr   )Ú
tqdm_classÚ	lock_nameÚold_lockÚlock© r   úT/var/www/html/CropPilot/venv/lib/python3.10/site-packages/tqdm/contrib/concurrent.pyÚensure_lock   s   €
r   c              	   O   sö   |  ¡ }d|vrt|d ƒ|d< | dt¡}| dtdtƒ d ƒ¡}| dd¡}| d	d
¡}t||d��=}	| ||j|	fd��#}
t||
j	|g|¢R d|iŽfi |¤ŽƒW  d  ƒ W  d  ƒ S 1 sdw   Y  W d  ƒ dS 1 stw   Y  dS )a  
    Implementation of `thread_map` and `process_map`.

    Parameters
    ----------
    tqdm_class  : [default: tqdm.auto.tqdm].
    max_workers  : [default: min(32, cpu_count() + 4)].
    chunksize  : [default: 1].
    lock_name  : [default: "":str].
    Útotalr   r   Úmax_workersé    é   Ú	chunksizeé   r   r   )r   )r   ÚinitializerÚinitargsN)
Úcopyr   ÚpopÚ	tqdm_autoÚminr   r   r   ÚlistÚmap)ÚPoolExecutorÚfnÚ	iterablesÚtqdm_kwargsÚkwargsr   r   r   r   ÚlkÚexr   r   r   Ú_executor_map   s"   ÿ&þþ"þr,   c                 O   s$   ddl m} t|| g|¢R i |¤ŽS )a¢  
    Equivalent of `list(map(fn, *iterables))`
    driven by `concurrent.futures.ThreadPoolExecutor`.

    Parameters
    ----------
    tqdm_class  : optional
        `tqdm` class to use for bars [default: tqdm.auto.tqdm].
    max_workers  : int, optional
        Maximum number of workers to spawn; passed to
        `concurrent.futures.ThreadPoolExecutor.__init__`.
        [default: max(32, cpu_count() + 4)].
    r   )ÚThreadPoolExecutor)Úconcurrent.futuresr-   r,   )r&   r'   r(   r-   r   r   r   r	   6   s   c                 O   s|   ddl m} |r&d|vr&ttt|ƒƒ}|dkr&ddlm} |d| tdd� d	|vr2| ¡ }d
|d	< t	|| g|¢R i |¤ŽS )a¦  
    Equivalent of `list(map(fn, *iterables))`
    driven by `concurrent.futures.ProcessPoolExecutor`.

    Parameters
    ----------
    tqdm_class  : optional
        `tqdm` class to use for bars [default: tqdm.auto.tqdm].
    max_workers  : int, optional
        Maximum number of workers to spawn; passed to
        `concurrent.futures.ProcessPoolExecutor.__init__`.
        [default: min(32, cpu_count() + 4)].
    chunksize  : int, optional
        Size of chunks sent to worker processes; passed to
        `concurrent.futures.ProcessPoolExecutor.map`. [default: 1].
    lock_name  : str, optional
        Member of `tqdm_class.get_lock()` to use [default: mp_lock].
    r   )ÚProcessPoolExecutorr   iè  )Úwarnz…Iterable length %d > 1000 but `chunksize` is not set. This may seriously degrade multiprocess performance. Set `chunksize=1` or more.r   )Ú
stacklevelr   Úmp_lock)
r.   r/   Úmaxr$   r   Úwarningsr0   r   r   r,   )r&   r'   r(   r/   Úlongest_iterable_lenr0   r   r   r   r
   H   s   þýN)r   )Ú__doc__Ú
contextlibr   Úoperatorr   Úosr   Úautor   r!   Ústdr   Ú
__author__Ú__all__r   r,   r	   r
   r   r   r   r   Ú<module>   s    
