
    .Phm                     h    d Z ddlmZmZ ddlmZ dad Z G d de          Z G d d	e          Z	dS )
zUtility function to construct a loky.ReusableExecutor with custom pickler.

This module provides efficient ways of working with data stored in
shared memory with numpy.memmap arrays without inducing any memory
copy between the parent and child processes.
   )TemporaryResourcesManagerget_memmapping_reducers)_ReusablePoolExecutorNc                 &    t          j        | fi |S N)MemmappingExecutorget_memmapping_executor)n_jobskwargss     O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/joblib/executor.pyr	   r	      s    5fGGGGG    c                   Z     e Zd Ze	 	 	 	 	 	 d fd	            Zd	dZed             Z xZS )
r   ,  N c           
         |                                 }	|	                    |r|ni            |	                    t          |||                     t          du p
t          |	k    }
|	at	          |          }t          dd|j        d|\  }}t                                          ||||
||||          \  }}|s||_	        ||j	        
                    |           |S )z_Factory for ReusableExecutor with automatic memmapping for large
        numpy arrays.
        )timeoutinitializerinitargsNT)unlink_on_gc_collecttemp_folder_resolver)job_reducersresult_reducersreuser   r   r   envr   )copyupdatedict_executor_argsr   r   resolve_temp_folder_namesuperget_reusable_executor_temp_folder_managerregister_new_context)clsr
   r   r   r   r   temp_folder
context_idbackend_argsexecutor_argsr   managerr   r   	_executorexecutor_is_reused	__class__s                   r   r	   z*MemmappingExecutor.get_memmapping_executor   s1   $ %))++C/SSR000kHMMM	
 	
 	
 $&I.M*I&+K88 )@ )
!%!(!A)
 )
 )
 )
%o
 ).(E(E%+# )F 	)
 	)
%	% " 	5
 .5I*! *??
KKKr   Fc                     |                      |           | j        5  | j                            |d           d d d            d S # 1 swxY w Y   d S )N)kill_workersT)forceallow_non_empty)shutdown_submit_resize_lockr"   _clean_temporary_resources)selfr.   s     r   	terminatezMemmappingExecutor.terminateU   s    <000 % 	 	%@@"D A   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                 |    t          | dd           | j        S | j                                        | _        | j        S )N_cached_temp_folder)getattrr7   r"   r   )r4   s    r   _temp_folderzMemmappingExecutor._temp_folderf   sG     4.55A++ )BBDD $ ++r   )r   Nr   NNN)F)	__name__
__module____qualname__classmethodr	   r5   propertyr9   __classcell__r,   s   @r   r   r      s         < < < < < [<|   " , , X, , , , ,r   r   c                   (     e Zd ZdZd Z fdZ xZS )_TestingMemmappingExecutorzWrapper around ReusableExecutor to ease memmapping testing with Pool
    and Executor. This is only for testing purposes.

    c                 :     | j         |g|R  }|j        |_        |S )zSchedule a func to be run)submitresultget)r4   funcargsfutures       r   apply_asyncz&_TestingMemmappingExecutor.apply_async|   s)    T)D)))]
r   c                 R    t           t                      j        |g|R            S r   )listr    map)r4   frH   r,   s      r   rM   z_TestingMemmappingExecutor.map   s)    KEGGK)D)))***r   )r:   r;   r<   __doc__rJ   rM   r?   r@   s   @r   rB   rB   v   sQ         
  + + + + + + + + +r   rB   )
rO   _memmapping_reducerr   r    externals.loky.reusable_executorr   r   r	   r   rB   r   r   r   <module>rR      s     T S S S S S S S C C C C C CH H H^, ^, ^, ^, ^,. ^, ^, ^,B+ + + + +!3 + + + + +r   