o
�J�hm � @ sP d Z ddlmZmZ ddlmZ dadd� ZG dd� de�ZG d d
� d
e�Z dS )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.
� )�TemporaryResourcesManager�get_memmapping_reducers)�_ReusablePoolExecutorNc K s t j| fi |��S �N)�MemmappingExecutor�get_memmapping_executor)�n_jobs�kwargs� r
�MC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\joblib\executor.pyr s r c sD e Zd Ze d� fdd� �Zddd�Zed d
� �Z� ZS )
r �, Nr
c
s� |� � } | �|r
|ni � | �t|||d�� tdu pt| k}
| at|�}tdd|jd�|��\}}
t� j|||
|
||||d�\}}|sG||_ |durQ|j �
|� |S )z_Factory for ReusableExecutor with automatic memmapping for large
numpy arrays.
)�timeout�initializer�initargsNT)Zunlink_on_gc_collectZtemp_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_managerZregister_new_context)�clsr r
r r r Ztemp_folder�
context_idZbackend_args�
executor_argsr �managerr r � _executorZexecutor_is_reused�� __class__r
r r s: ��
�
�z*MemmappingExecutor.get_memmapping_executorFc C sH | j |d� | j� | jj|dd� W d � d S 1 sw Y d S )N)�kill_workersT)�forceZallow_non_empty)�shutdown�_submit_resize_lockr �_clean_temporary_resources)�selfr# r
r
r � terminateU s �"�zMemmappingExecutor.terminatec C s( t | dd �d ur| jS | j�� | _| jS )N�_cached_temp_folder)�getattrr* r r )r( r
r
r �_temp_folderf s
�zMemmappingExecutor._temp_folder)r Nr
NNN)F) �__name__�
__module__�__qualname__�classmethodr r) �propertyr, �
__classcell__r
r
r! r r s �
>r c s( e Zd ZdZdd� Z� fdd�Z� ZS )�_TestingMemmappingExecutorzWrapper around ReusableExecutor to ease memmapping testing with Pool
and Executor. This is only for testing purposes.
c C s | j |g|�R � }|j|_|S )zSchedule a func to be run)�submit�result�get)r( �func�args�futurer
r
r �apply_async| s z&_TestingMemmappingExecutor.apply_asyncc s t t� j|g|�R � �S r )�listr �map)r( �fr8 r! r
r r<