
    j              
           d dl Z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gZddee
ge
f         dee
         d	edz  d
ee
         fdZdS )    N)CallableIterableIterator)
ThreadPool)Any)ENV_VARS_TRUE_VALUESmultithread_execfuncseqthreadsreturnc                    t          |t                    r|n t          dt          j                              }|dk     s9t
          j                            dd                                          t          v rt          | |          }nLt          |          5 }t          d |
                    | |                    }ddd           n# 1 swxY w Y   |S )aO  Execute a given function in parallel for each element of a given sequence

    >>> from doctr.utils.multithreading import multithread_exec
    >>> entries = [1, 4, 8]
    >>> results = multithread_exec(lambda x: x ** 2, entries)

    Args:
        func: function to be executed on each element of the iterable
        seq: iterable
        threads: number of workers to be used for multiprocessing

    Returns:
        iterator of the function's results using the iterable as inputs

    Notes:
        This function uses ThreadPool from multiprocessing package, which uses `/dev/shm` directory for shared memory.
        If you do not have write permissions for this directory (if you run `doctr` on AWS Lambda for instance),
        you might want to disable multiprocessing. To achieve that, set 'DOCTR_MULTIPROCESSING_DISABLE' to 'TRUE'.
          DOCTR_MULTIPROCESSING_DISABLE c                     | S N )xs    ]/var/www/html/Carbon-Document/venv/lib/python3.11/site-packages/doctr/utils/multithreading.py<lambda>z"multithread_exec.<locals>.<lambda>/   s    A     N)
isinstanceintminmp	cpu_countosenvirongetupperr   mapr   )r
   r   r   resultstps        r   r	   r	      s    ( $GS11Nggs2r|~~7N7NG{{bjnn%DbIIOOQQUiiidC..    	:B ++rvvdC'8'899G	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: Ns   &C

CCr   )multiprocessingr   r   collections.abcr   r   r   multiprocessing.poolr   typingr   doctr.file_utilsr   __all__r   r	   r   r   r   <module>r,      s        				 8 8 8 8 8 8 8 8 8 8 + + + + + +       1 1 1 1 1 1
 8SE3J/ hsm cTXj dlmpdq      r   