U
    +|j˜  ã                   @   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k
r¨   dZY nX dZdZedd„ ƒZddd„Zddd„Zddd„Zerêe ZZn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   s*   z
| V  W 5 |   ¡  |  ¡  |  ¡  X dS )z>Return a context manager making sure the pool closes properly.N)ÚcloseÚjoinÚ	terminater   © r   údC:\Users\snmko\Desktop\web_content\django_cbt\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.
    )Úmap)ÚfuncÚiterableÚ	chunksizer   r   r   Ú_map_fallback<   s    r   c              
   C   s0   t tƒ ƒ�}| | ||¡W  5 Q R £ S Q R X 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   s2   t ttƒƒ�}| | ||¡W  5 Q R £ S Q R X 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   )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>   s2   





