o �J�hm�@sPdZddlmZmZddlmZdadd�ZGdd�de�ZGd 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)�_ReusablePoolExecutorNcKstj|fi|��S�N)�MemmappingExecutor�get_memmapping_executor)�n_jobs�kwargs�r �MC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\joblib\executor.pyrsrcsDeZdZe      d �fdd� �Zd dd�Zed d ��Z�ZS) r�,Nr c s�|��} | �|r |ni�| �t|||d��tdupt| 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 rr�envr ) �copy�update�dict�_executor_argsrr�resolve_temp_folder_name�super�get_reusable_executor�_temp_folder_managerZregister_new_context)�clsrr rrrZ temp_folder� context_idZ backend_args� executor_argsr�managerrr� _executorZexecutor_is_reused�� __class__r r rs: �� � �  z*MemmappingExecutor.get_memmapping_executorFcCsH|j|d�|j�|jj|dd�Wd�dS1swYdS)N)� kill_workersT)�forceZallow_non_empty)�shutdown�_submit_resize_lockr�_clean_temporary_resources)�selfr#r r r � terminateUs  �"�zMemmappingExecutor.terminatecCs(t|dd�dur |jS|j��|_|jS)N�_cached_temp_folder)�getattrr*rr)r(r r r � _temp_folderfs �zMemmappingExecutor._temp_folder)r Nr NNN)F) �__name__� __module__� __qualname__� classmethodrr)�propertyr,� __classcell__r r r!r rs� >rcs(eZdZdZdd�Z�fdd�Z�ZS)�_TestingMemmappingExecutorzWrapper around ReusableExecutor to ease memmapping testing with Pool and Executor. This is only for testing purposes. cCs|j|g|�R�}|j|_|S)zSchedule a func to be run)�submit�result�get)r(�func�args�futurer r r � apply_async|sz&_TestingMemmappingExecutor.apply_asynccstt�j|g|�R��Sr)�listr�map)r(�fr8r!r r r<�sz_TestingMemmappingExecutor.map)r-r.r/�__doc__r:r<r2r r r!r r3vsr3) r>Z_memmapping_reducerrrZ externals.loky.reusable_executorrrrrr3r r r r �<module>s a
Memory