U
    be	                     @   s   d Z ddlZddlZddlZeeZdZzddlZ	dZW n e
k
rX   ed Y nX dZzddlZdZW n e
k
r   ed Y nX G dd deZG d	d
 d
eZejdddZdS )z^Common functionality for concurrent processing.

The main entry point is :func:`create_pool`.
    NFTz:concurrent.futures could not be imported and won't be usedz7multiprocessing could not be imported and won't be usedc                   @   s    e Zd ZdZdd Zdd ZdS )	DummyPoolz?A class that mimics multiprocessing.pool.Pool for our purposes.c                 C   s
   t ||S N)map)selffunctionitems r   X/var/www/html/services/stratfitenv/lib/python3.8/site-packages/smart_open/concurrency.pyimap_unordered+   s    zDummyPool.imap_unorderedc                 C   s   d S r   r   r   r   r   r	   	terminate.   s    zDummyPool.terminateN)__name__
__module____qualname____doc__r
   r   r   r   r   r	   r   )   s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ConcurrentFuturesPoolz_A class that mimics multiprocessing.pool.Pool but uses concurrent futures instead of processes.c                 C   s   t j|| _d S r   )
concurrentfuturesThreadPoolExecutorexecutor)r   max_workersr   r   r	   __init__4   s    zConcurrentFuturesPool.__init__c                 #   s4    fdd|D }t j|D ]}| V  q d S )Nc                    s   g | ]}j  |qS r   )r   submit).0itemr   r   r   r	   
<listcomp>8   s     z8ConcurrentFuturesPool.imap_unordered.<locals>.<listcomp>)r   r   as_completedresult)r   r   r   r   futurer   r   r	   r
   7   s    z$ConcurrentFuturesPool.imap_unorderedc                 C   s   | j jdd d S )NT)wait)r   shutdownr   r   r   r	   r   <   s    zConcurrentFuturesPool.terminateN)r   r   r   r   r   r
   r   r   r   r   r	   r   2   s   r      c                 c   sf   t r$| r$td|  tjj| d}n0trD| rDtd|  t| d}ntd t }|V  |	  d S )Nz-creating multiprocessing pool with %i workers)	processesz0creating concurrent futures pool with %i workers)r   zcreating dummy pool)
_MULTIPROCESSINGloggerinfomultiprocessingpoolZPool_CONCURRENT_FUTURESr   r   r   )r#   r(   r   r   r	   create_pool@   s    
r*   )r"   )r   
contextlibloggingwarnings	getLoggerr   r%   r)   concurrent.futuresr   ImportErrorwarnr$   Zmultiprocessing.poolr'   objectr   r   contextmanagerr*   r   r   r   r	   <module>	   s(   
	