ó
    È9iV	  ã                   ór   • 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4S\S	\S
\4S jjrg)é    )ÚThreadPoolExecutorÚas_completed©Úwraps)Útqdm)ÚDEFAULT_MAX_WORKERS)Ú
get_loggerFNÚmax_workersÚdisable_tqdmÚ	tqdm_descc                 ó   ^ ^^• 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                 ó8   >^ • [        T 5      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[	        U5       H3  nUR                  S5        UR                  UR                  5       5        M5     S S S 5        S S S 5        U$ s  snf ! , (       d  f       N= f! , (       d  f       U$ = f)	NTi   r   zProcessing z items)Ú
unit_scaleÚunit_divisorÚinitialÚtotalÚdescÚdisable)r
   é   )r   Úlenr   Úsubmitr   ÚupdateÚappendÚresult)ÚiterableÚargsÚkwargsÚresultsÚpbarÚexecutorÚitemÚfuturesÚfuturer   Úfuncr
   r   s            €€€€Ú]/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/utils/thread_utils.pyÚwrapperÚ3thread_executor.<locals>.decorator.<locals>.wrapper+   sä   ø€ àˆGäØ#Ø!%ØÜ˜h›-Ø"×I¨´C¸³M°?À&Ð&IØ(òð ä'°KÒ@ÀHñ %-óâ$,˜Dð !Ÿš¨¨dÐD°TÒD¸VÑDÀdÒJÙ$,ð ð ô #/¨wÖ"7˜ØŸ™ AœØŸ™ v§}¡}£Ö7ñ #8÷ A÷ð( ˆNùò÷ AÕ@ú÷ô ð( ˆNús5   ±
C»B=Á "B8Á"AB=Â&CÂ8B=Â=
C	ÃCÃ
Cr   )r%   r'   r   r
   r   s   ` €€€r&   Ú	decoratorÚ"thread_executor.<locals>.decorator)   s    ù€ ä	ˆt‹÷	ó 
ð	ð2 ˆó    © )r
   r   r   r)   s   ``` r&   Úthread_executorr-      s   ú€ ÷6ð< Ðr+   )Úconcurrent.futuresr   r   Ú	functoolsr   Ú	tqdm.autor   Úmodelscope.hub.constantsr   Úmodelscope.utils.loggerr	   ÚloggerÚintÚboolÚstrr-   r,   r+   r&   Ú<module>r7      sE   ð÷ @Ý å å 8Ý .á	‹€ð (;Ø).Ø%)ñ9 ð 9Ø"&ð9à"ö9r+   