3 ”ReL ã @ s& d Z ddgZddlmZ ddlmZ ddlmZ ddl m Z ddlmZ ddl mZ dd lmZ er¬dd lmZmZmZmZmZ ddlmZ eejejf ZedƒZed ƒZyddlZW n ek rÐ dZY nX dZdZedd„ ƒZddd„Zddd„Z ddd„Z!e�se�re Z"Z#ne Z"e!Z#dS )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)ÚCallableÚIterableÚIteratorÚUnionÚTypeVar)ÚpoolÚSÚTNTFi€„ c c s* z | V W d| j ƒ | jƒ | jƒ X dS )z>Return a context manager making sure the pool closes properly.N)ÚcloseÚjoinÚ terminate)r © r ú‹/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/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ƒ ƒ�}|j| ||ƒS Q R X dS )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&