
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
U
    ¡ê,a@"  ã                   @   s¢   d Z dZddlZddlmZ ddlZddlZddlZddlZddl	Z	e 
¡ Zdadd„ Ze e¡ G dd	„ d	eƒZd
d„ ZG dd„ dejƒZG dd„ dejƒZdS )zImplements ThreadPoolExecutor.z"Brian Quinlan (brian@sweetapp.com)é    N)Ú_baseFc                  C   sB   da tt ¡ ƒ} | D ]\}}| d ¡ q| D ]\}}| ¡  q,d S ©NT)Ú	_shutdownÚlistÚ_threads_queuesÚitemsÚputÚjoin)r   ÚtÚq© r   ú>/opt/alt/python38/lib64/python3.8/concurrent/futures/thread.pyÚ_python_exit!   s    r   c                   @   s   e Zd Zdd„ Zdd„ ZdS )Ú	_WorkItemc                 C   s   || _ || _|| _|| _d S ©N)ÚfutureÚfnÚargsÚkwargs)Úselfr   r   r   r   r   r   r   Ú__init__.   s    z_WorkItem.__init__c              
   C   sf   | j  ¡ sd S z| j| j| jŽ}W n2 tk
rT } z| j  |¡ d } W 5 d }~X Y nX | j  |¡ d S r   )r   Zset_running_or_notify_cancelr   r   r   ÚBaseExceptionÚset_exceptionZ
set_result)r   ÚresultÚexcr   r   r   Úrun4   s    
z_WorkItem.runN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   -   s   r   c                 C   sô   |d k	rRz||Ž  W n< t k
rP   tjjddd� | ƒ }|d k	rJ| ¡  Y d S X zx|jdd�}|d k	rŽ| ¡  ~| ƒ }|d k	rŠ|j ¡  ~qT| ƒ }t	s¦|d ks¦|j	rÄ|d k	r´d|_	| 
d ¡ W d S ~qTW n$ t k
rî   tjjddd� Y nX d S )NzException in initializer:T)Úexc_info)ÚblockzException in worker)r   r   ZLOGGERZcriticalÚ_initializer_failedÚgetr   Ú_idle_semaphoreÚreleaser   r   )Zexecutor_referenceZ
work_queueÚinitializerÚinitargsZexecutorÚ	work_itemr   r   r   Ú_workerB   s8    

r(   c                   @   s   e Zd ZdZdS )ÚBrokenThreadPoolzR
    Raised when a worker thread in a ThreadPoolExecutor failed initializing.
    N)r   r   r   Ú__doc__r   r   r   r   r)   m   s   r)   c                   @   sf   e Zd Ze ¡ jZddd„Zdd„ Ze	j
jje_e	j
jje_dd	„ Zd
d„ Zddd„Ze	j
jje_dS )ÚThreadPoolExecutorNÚ r   c                 C   s¢   |dkrt dt ¡ pdd ƒ}|dkr.tdƒ‚|dk	rFt|ƒsFtdƒ‚|| _t ¡ | _	t
 d¡| _tƒ | _d| _d| _t
 ¡ | _|pŽd	|  ¡  | _|| _|| _dS )
a•  Initializes a new ThreadPoolExecutor instance.

        Args:
            max_workers: The maximum number of threads that can be used to
                execute the given calls.
            thread_name_prefix: An optional name prefix to give our threads.
            initializer: A callable used to initialize worker threads.
            initargs: A tuple of arguments to pass to the initializer.
        Né    é   é   r   z"max_workers must be greater than 0zinitializer must be a callableFzThreadPoolExecutor-%d)ÚminÚosÚ	cpu_countÚ
ValueErrorÚcallableÚ	TypeErrorÚ_max_workersÚqueueZSimpleQueueÚ_work_queueÚ	threadingZ	Semaphorer#   ÚsetÚ_threadsÚ_brokenr   ZLockÚ_shutdown_lockÚ_counterÚ_thread_name_prefixÚ_initializerÚ	_initargs)r   Zmax_workersZthread_name_prefixr%   r&   r   r   r   r   x   s$    


ÿzThreadPoolExecutor.__init__c               
   O   sä   t | ƒdkr| ^}}} nV| s&tdƒ‚nHd|krZ| d¡}| ^}} dd l}|jdtdd� ntdt | ƒd  ƒ‚|j�f |jr†t|jƒ‚|j	r”t
d	ƒ‚t	r t
d
ƒ‚t ¡ }t||| |ƒ}|j |¡ | ¡  |W  5 Q R £ S Q R X d S )Né   zDdescriptor 'submit' of 'ThreadPoolExecutor' object needs an argumentr   r   z.Passing 'fn' as keyword argument is deprecated)Ú
stacklevelz6submit expected at least 1 positional argument, got %dr.   z*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdown)Úlenr5   ÚpopÚwarningsÚwarnÚDeprecationWarningr=   r<   r)   r   ÚRuntimeErrorr   ZFuturer   r8   r   Ú_adjust_thread_count)r   r   r   r   rF   ÚfÚwr   r   r   Úsubmitž   s6    

 ÿ
ÿ
zThreadPoolExecutor.submitc                 C   s”   | j jdd�rd S | jfdd„}t| jƒ}|| jk r�d| jp>| |f }tj|t	t
 | |¡| j| j| jfd�}d|_| ¡  | j |¡ | jt|< d S )Nr   )Ztimeoutc                 S   s   |  d ¡ d S r   )r   )Ú_r   r   r   r   Ú
weakref_cbÈ   s    z;ThreadPoolExecutor._adjust_thread_count.<locals>.weakref_cbz%s_%d)ÚnameÚtargetr   T)r#   Úacquirer8   rD   r;   r6   r?   r9   ZThreadr(   ÚweakrefÚrefr@   rA   ZdaemonÚstartÚaddr   )r   rO   Znum_threadsZthread_namer
   r   r   r   rJ   Á   s&    


ÿ
ýÿz'ThreadPoolExecutor._adjust_thread_countc              	   C   sb   | j �R d| _z| j ¡ }W n tjk
r6   Y qTY nX |d k	r|j t| jƒ¡ qW 5 Q R X d S )NzBA thread initializer failed, the thread pool is not usable anymore)	r=   r<   r8   Z
get_nowaitr7   ZEmptyr   r   r)   )r   r'   r   r   r   r!   Ù   s    
z&ThreadPoolExecutor._initializer_failedTc              	   C   s@   | j � d| _| j d ¡ W 5 Q R X |r<| jD ]}| ¡  q.d S r   )r=   r   r8   r   r;   r	   )r   Úwaitr
   r   r   r   Úshutdownæ   s    
zThreadPoolExecutor.shutdown)Nr,   Nr   )T)r   r   r   Ú	itertoolsÚcountÚ__next__r>   r   rM   r   ÚExecutorÚ__text_signature__r*   rJ   r!   rX   r   r   r   r   r+   s   s   
    ÿ
& 
r+   )r*   Ú
__author__ÚatexitZconcurrent.futuresr   rY   r7   r9   rS   r1   ÚWeakKeyDictionaryr   r   r   ÚregisterÚobjectr   r(   ZBrokenExecutorr)   r\   r+   r   r   r   r   Ú<module>   s    	
+