o
    |ŸŽiý  ã                   @   sö   d Z ddgZddlmZ ddlmZ ddlmZ ddlmZ	 ddl
mZmZmZmZmZ ddlmZ eejej	f Zed	ƒZed
ƒZzddlZW n eyS   dZY nw dZdZedd„ ƒZddd„Zddd„Zddd„Zerue ZZdS eZeZdS )ab  Convenient parallelization of higher order functions.

This module provides two helper functions, with appropriate fallbacks on
Python 2 and on systems lacking support for synchronization mechanisms:

- map_multiprocess
- map_multithread

These helpers work like Python 3's map, with two differences:

- They don't guarantee the order of processing of
  the elements of the iterable.
- The underlying process/thread pools chop the iterable into
  a number of chunks, so that for very long iterables using
  a large value for chunksize can make the job complete much faster
  than using the default value of 1.
Úmap_multiprocessÚmap_multithreadé    )Úcontextmanager)ÚPool©Úpool)ÚCallableÚIterableÚIteratorÚTypeVarÚUnion)ÚDEFAULT_POOLSIZEÚSÚTNTFi€„ c                 c   sB   � z| V  W |   ¡  |  ¡  |  ¡  dS |   ¡  |  ¡  |  ¡  w )z>Return a context manager making sure the pool closes properly.N)ÚcloseÚjoinÚ	terminater   © r   úfC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\pip/_internal/utils/parallel.pyÚclosing.   s   €þ
r   é   c                 C   s
   t | |ƒS )zÞMake an iterator applying func to each element in iterable.

    This function is the sequential fallback either on Python 2
    where Pool.imap* doesn't react to KeyboardInterrupt
    or when sem_open is unavailable.
    N)Úmap)ÚfuncÚiterableÚ	chunksizer   r   r   Ú_map_fallback<   s   
r   c                 C   s<   t tƒ ƒ�}| | ||¡W  d  ƒ S 1 sw   Y  dS )zÿChop iterable into chunks and submit them to a process pool.

    For very long iterables using a large value for chunksize can make
    the job complete much faster than using the default value of 1.

    Return an unordered iterator of the results.
    N)r   ÚProcessPoolÚimap_unordered©r   r   r   r   r   r   r   Ú_map_multiprocessG   s   	$ÿr   c                 C   s>   t ttƒƒ�}| | ||¡W  d  ƒ S 1 sw   Y  dS )zþChop iterable into chunks and submit them to a thread pool.

    For very long iterables using a large value for chunksize can make
    the job complete much faster than using the default value of 1.

    Return an unordered iterator of the results.
    N)r   Ú
ThreadPoolr   r   r   r   r   r   Ú_map_multithreadT   s   	$ÿr!   )r   )Ú__doc__Ú__all__Ú
contextlibr   Úmultiprocessingr   r   r   Zmultiprocessing.dummyr    Útypingr   r	   r
   r   r   Zpip._vendor.requests.adaptersr   r   r   Zmultiprocessing.synchronizeÚImportErrorZLACK_SEM_OPENÚTIMEOUTr   r   r   r!   r   r   r   r   r   r   Ú<module>   s6    ÿ



