o
    'jc                     @   s*   d dl m Z  d dlmZmZ dddZdS )	    )tqdm)ProcessPoolExecutoras_completed   Fc                    sL  |dkr fdd| d| D }ng }|dkr+| fddt | |d D  S t|d=rB fdd| |d D }n fd	d| |d D }t|d
ddd}t t|fi |D ]}qcW d   n1 spw   Y  g }	t t|D ]$\}
}z	|	|  W q} ty } z|	| W Y d}~q}d}~ww ||	 S )a  
        A parallel version of the map function with a progress bar.
        Args:
            array (array-like): An array to iterate over.
            function (function): A python function to apply to the elements of array
            n_jobs (int, default=16): The number of cores to use
            use_kwargs (boolean, default=False): Whether to consider the elements of array as dictionaries of
                keyword arguments to function
            front_num (int, default=3): The number of iterations to run serially before kicking off the parallel job.
                Useful for catching bugs
        Returns:
            [function(array[0]), function(array[1]), ...]
    r   c                    &   g | ]}r d i |n |qS  r   .0afunction
use_kwargsr   r/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddleocr/ppstructure/table/table_metric/parallel.py
<listcomp>   s    z$parallel_process.<locals>.<listcomp>N   c                    r   r   r   r	   r   r   r   r      s   & )max_workersc                    s   g | ]}j  fi |qS r   Zsubmitr	   r   poolr   r   r       s    c                    s   g | ]}  |qS r   r   r	   r   r   r   r   "   s    itT)totalunitZ
unit_scaleZleave)r   r   lenr   	enumerateappendresult	Exception)arrayr   Zn_jobsr   Z	front_numZfrontZfutureskwargsfoutifutureer   )r   r   r   r   parallel_process   s:   
$r%   N)r   Fr   )r   concurrent.futuresr   r   r%   r   r   r   r   <module>   s    