o
    1 i  ã                   @   s~   d dl Z d dlmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlZd dlmZ d dlmZ e  e¡ZG dd	„ d	eƒZdS )
é    N)ÚAnyÚDictÚOptional)ÚParallel)ÚMultiprocessingBackend)ÚPicklingPool)Ú	usage_lib)ÚPoolc                       sœ   e Zd ZdZ			ddee dee deeeef  f‡ fdd„Z						dd	ed
ee
 dee dee deeeef  f
‡ fdd„Z‡ fdd„Z‡  ZS )Ú
RayBackendz‡Ray backend uses ray, a system for scalable distributed computing.
    More info about Ray is available here: https://docs.ray.io.
    NÚnesting_levelÚinner_max_num_threadsÚray_remote_argsc                    s,   t  d¡ || _tƒ jd||dœ|¤Ž dS )zT``ray_remote_args`` will be used to configure Ray Actors
        making up the pool.zutil.joblib)r   r   N© )r   Zrecord_library_usager   ÚsuperÚ__init__)Úselfr   r   r   Úkwargs©Ú	__class__r   úg/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/ray/util/joblib/ray_backend.pyr      s   
	þ
ýzRayBackend.__init__é   Ún_jobsÚparallelÚpreferÚrequirec           
         s¢   t ft_	 |dkr7t ¡ s+ddl}d|jv r"t d 	|jd ¡¡ nt d¡ t 
¡  ttjj ¡ d ƒ}|}tt| ƒj||||fd|durH|n| ji|¤Ž}	|	S )	a§  Make Ray Pool the father class of PicklingPool. PicklingPool is a
        father class that inherits Pool from multiprocessing.pool. The next
        line is a patch, which changes the inheritance of Pool to be from
        ray.util.multiprocessing.pool.

        ``ray_remote_args`` will be used to configure Ray Actors making up the pool.
        This will override ``ray_remote_args`` set during initialization.
        éÿÿÿÿr   NZRAY_ADDRESSz)Connecting to ray cluster at address='{}'zStarting local ray clusterÚCPUr   )r	   r   Ú	__bases__ÚrayZis_initializedÚosÚenvironÚloggerÚinfoÚformatÚinitÚintÚ_privateÚstateÚcluster_resourcesr   r
   Ú	configurer   )
r   r   r   r   r   r   Zmemmappingpool_argsr   Úray_cpusÚ
eff_n_jobsr   r   r   r)   )   s8   
ÿÿ

üÿùø
zRayBackend.configurec                    s4   t t| ƒ |¡}|dkrttjj ¡ d ƒ}|}|S )Nr   r   )r   r
   Úeffective_n_jobsr%   r   r&   r'   r(   )r   r   r+   r*   r   r   r   r,   [   s
   zRayBackend.effective_n_jobs)NNN)r   NNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r%   r   Ústrr   r   r   r)   r,   Ú__classcell__r   r   r   r   r
      s:    üþýüúþýüûú2r
   )ÚloggingÚtypingr   r   r   Zjoblibr   Zjoblib._parallel_backendsr   Zjoblib.poolr   r   Zray._common.usager   Zray.util.multiprocessing.poolr	   Ú	getLoggerr-   r!   r
   r   r   r   r   Ú<module>   s    
