o
    l¨Êh0  ã                   @   sT   d Z ddlZddlmZ ddlmZ ddlmZ da		dd	d
„Z	G dd„ dƒZ
dS )zÿUtility 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.
é    Né   )Údelete_folder)Úget_memmapping_reducers)Úget_reusable_executoré,  © c              
   K   s    |  ¡ }| |r
|ni ¡ | t|||d�¡ tdu pt|k}|at dtdƒ¡}t|fi |¤Ž\}	}
}t| |	|
|||||d�}t	|dƒsJ||_
|S t|ƒ |S )zWFactory for ReusableExecutor with automatic memmapping for large numpy
    arrays.
    )ÚtimeoutÚinitializerÚinitargsNr   g    _ B)Újob_reducersÚresult_reducersÚreuser   r	   r
   ÚenvÚ_temp_folder)ÚcopyÚupdateÚdictÚ_executor_argsÚrandomÚrandintÚintr   r   Úhasattrr   r   )Ún_jobsr   r	   r
   r   Úbackend_argsÚexecutor_argsr   Úid_executorr   r   Útemp_folderÚ	_executorr   r   úA/var/www/html/env/lib/python3.10/site-packages/joblib/executor.pyÚget_memmapping_executor   s0   ÿÿÿü
ÿr   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú_TestingMemmappingExecutorz~Wrapper around ReusableExecutor to ease memmapping testing with Pool
    and Executor. This is only for testing purposes.
    c                 K   s    t |fi |¤Ž| _| jj| _d S ©N)r   r   r   )Úselfr   r   r   r   r   Ú__init__9   s   z#_TestingMemmappingExecutor.__init__c                 C   s    | j j|g|¢R Ž }|j|_|S )zSchedule a func to be run)r   ÚsubmitÚresultÚget)r"   ÚfuncÚargsÚfuturer   r   r   Úapply_async=   s   z&_TestingMemmappingExecutor.apply_asyncc                 C   s   | j  ¡  t| jƒ d S r!   )r   Úshutdownr   r   )r"   r   r   r   Ú	terminateC   s   
z$_TestingMemmappingExecutor.terminatec                 G   s   | j j|g|¢R Ž }t|ƒS r!   )r   ÚmapÚlist)r"   Úfr(   Úresr   r   r   r-   G   s   z_TestingMemmappingExecutor.mapN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r*   r,   r-   r   r   r   r   r    5   s    r    )r   Nr   N)r4   r   Údiskr   Ú_memmapping_reducerr   Ú externals.loky.reusable_executorr   r   r   r    r   r   r   r   Ú<module>   s    

ÿ!