a
    ”¼deL  ã                   @   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 ddlmZ dd	lmZ er¬dd
lmZ ddlmZmZmZmZmZ eejejf ZedƒZedƒZzddlZW n eyÎ   dZY n0 dZdZedd„ ƒZddd„Zddd„Z ddd„Z!e�s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)ÚDEFAULT_POOLSIZE)ÚPY2©Úmap)ÚMYPY_CHECK_RUNNING©Úpool)ÚCallableÚIterableÚIteratorÚTypeVarÚUnionÚSÚTNTFi€„ c                 c   sB   z"| V  W |   ¡  |  ¡  |  ¡  n|   ¡  |  ¡  |  ¡  0 dS )z>Return a context manager making sure the pool closes properly.N)ÚcloseÚjoinÚ	terminater   © r   úU/var/www/sistema_ama/venv/lib/python3.9/site-packages/pip/_internal/utils/parallel.pyÚclosing4   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.
    r   )ÚfuncÚiterableÚ	chunksizer   r   r   Ú_map_fallbackB   s    r   c                 C   s<   t tƒ ƒ�}| | ||¡W  d  ƒ S 1 s.0    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_multiprocessM   s    	r"   c                 C   s>   t ttƒƒ�}| | ||¡W  d  ƒ S 1 s00    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_multithreadZ   s    	r$   )r   )r   )r   )$Ú__doc__Ú__all__Ú
contextlibr   Úmultiprocessingr   r   Zmultiprocessing.dummyr#   Úpip._vendor.requests.adaptersr   Zpip._vendor.sixr   Zpip._vendor.six.movesr	   Úpip._internal.utils.typingr
   r   Útypingr   r   r   r   r   r   r   Zmultiprocessing.synchronizeÚImportErrorZLACK_SEM_OPENÚTIMEOUTr   r   r"   r$   r   r   r   r   r   r   Ú<module>   s:   





