
    6pj              	       x    S SK JrJr  S SKJr  S SKJr  S SKJr  S SK	J
r
  \
" 5       r\SSS4S\S	\S
\S\4S jjrg)    )ThreadPoolExecutoras_completedwraps)tqdm)DEFAULT_MAX_WORKERS)
get_loggerFNmax_workersdisable_tqdm	tqdm_descfault_tolerantc                     ^ ^^^ UUU U4S jnU$ )a  
A decorator to execute a function in a threaded manner using ThreadPoolExecutor.

Args:
    max_workers (int): The maximum number of threads to use.
    disable_tqdm (bool): disable progress bar.
    tqdm_desc (str): Desc of tqdm.

Returns:
    function: A wrapped function that executes with threading and a progress bar.

Examples:
    >>> from modelscope.utils.thread_utils import thread_executor
    >>> import time
    >>> @thread_executor(max_workers=8)
    ... def process_item(item, x, y):
    ...     # do something to single item
    ...     time.sleep(1)
    ...     return str(item) + str(x) + str(y)

    >>> items = [1, 2, 3]
    >>> process_item(items, x='abc', y='xyz')
c                 :   >^  [        T 5      UUU UU4S j5       nU$ )Nc           
        > / n[        SSS[        U 5      T=(       d    S[        U 5       S3TS9 n[        TS9 nU  Vs0 s H  nUR                  " TU/UQ70 UD6U_M     nn/ n[	        U5       H\  n	UR                  S5        T(       a"   UR                  U	R                  5       5        M=  UR                  U	R                  5       5        M^     S S S 5        S S S 5        T(       a  UW4$ U$ s  snf ! [         a<  n
Xy   n[        R                  S	U S
U
 35        UR                  Xj45         S n
A
M  S n
A
ff = f! , (       d  f       Nq= f! , (       d  f       Nz= f)NTi   r   zProcessing z items)
unit_scaleunit_divisorinitialtotaldescdisable)r
      zTask failed for z: )r   lenr   submitr   updateappendresult	Exceptionloggererror)iterableargskwargsresultspbarexecutoritemfuturesfailed_itemsfutureer   r   funcr
   r   s              Y/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/modelscope/utils/thread_utils.pywrapper3thread_executor.<locals>.decorator.<locals>.wrapper,   sR   G#!%h-"ICM?&&I( 'K@H %-$,D !dDTDVDdJ$,   $&L".w"7A)? 'v}} ? $NN6==?; #8 A: ,,N) $- ?'. &/?vRs-K L , 3 3TI > >? A@ s^   
ED< "C."*D<C3,%D<E.D<3
D9	=1D4	.D<4D9	9D<<
E
	E
Er   )r+   r-   r   r   r
   r   s   ` r,   	decorator"thread_executor.<locals>.decorator*   s&    	t"	 "	 
"	H      )r
   r   r   r   r/   s   ```` r,   thread_executorr3      s    8' 'R r1   )concurrent.futuresr   r   	functoolsr   	tqdm.autor   modelscope.hub.constantsr   modelscope.utils.loggerr	   r   intboolstrr3   r2   r1   r,   <module>r<      sW    @   8 .	 (;).%)+0E E"&E"E %)Er1   