B S��jA�@s�dZdZddlZddlmZddlZddlZddlZddlZddl Z e� �Z da dd�Z e�e �Gdd �d e�Zd d �ZGd d �d ej�ZGdd�dej�ZdS)zImplements ThreadPoolExecutor.z"Brian Quinlan (brian@sweetapp.com)�N)�_baseFcCsJdatt���}x|D]\}}|�d�qWx|D]\}}|��q2WdS)NT)� _shutdown�list�_threads_queues�items�put�join)r�t�q�r �>/opt/alt/python37/lib64/python3.7/concurrent/futures/thread.py� _python_exit!s  r c@seZdZdd�Zdd�ZdS)� _WorkItemcCs||_||_||_||_dS)N)�future�fn�args�kwargs)�selfrrrrr r r �__init__.sz_WorkItem.__init__c Csf|j��sdSy|j|j|j�}Wn2tk rT}z|j�|�d}Wdd}~XYnX|j�|�dS)N)rZset_running_or_notify_cancelrrr� BaseException� set_exceptionZ set_result)r�result�excr r r �run4s  z _WorkItem.runN)�__name__� __module__� __qualname__rrr r r r r-srcCs�|dk rPy ||�Wn:tk rNtjjddd�|�}|dk rJ|��dSXy`xZ|jdd�}|dk rt|��~qT|�}ts�|dks�|jr�|dk r�d|_|�d�dS~qTWWn$tk r�tjjddd�YnXdS)NzException in initializer:T)�exc_info)�blockzException in worker) rrZLOGGERZcritical�_initializer_failed�getrrr)Zexecutor_referenceZ work_queue� initializer�initargsZexecutor� work_itemr r r �_workerBs2    r$c@seZdZdZdS)�BrokenThreadPoolzR Raised when a worker thread in a ThreadPoolExecutor failed initializing. N)rrr�__doc__r r r r r%fsr%c@sZeZdZe��jZddd�Zdd�Ze j jj e_ dd �Z d d �Z dd d�Ze j jj e_ dS)�ThreadPoolExecutorN�r cCs�|dkrt��pdd}|dkr(td��|dk r@t|�s@td��||_t��|_t �|_ d|_ d|_ t ��|_|p|d|��|_||_||_dS) 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��rz"max_workers must be greater than 0zinitializer must be a callableFzThreadPoolExecutor-%d)�os� cpu_count� ValueError�callable� TypeError� _max_workers�queueZ SimpleQueue� _work_queue�set�_threads�_brokenr� threadingZLock�_shutdown_lock�_counter�_thread_name_prefix� _initializer� _initargs)rZ max_workersZthread_name_prefixr!r"r r r rqs   zThreadPoolExecutor.__init__c Os�t|�dkr|^}}}n>|s&td��n0d|krB|�d�}|^}}ntdt|�d��|j�Z|jrnt|j��|jr|td��tr�td��t� �}t ||||�}|j � |�|� �|SQRXdS)N�zDdescriptor 'submit' of 'ThreadPoolExecutor' object needs an argumentrz6submit expected at least 1 positional argument, got %dr)z*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdown)�lenr/�popr7r5r%r� RuntimeErrorrZFuturerr2r�_adjust_thread_count)rrrr�f�wr r r �submit�s*       zThreadPoolExecutor.submitcCs�|jfdd�}t|j�}||jkr~d|jp,||f}tj|tt� ||�|j|j |j fd�}d|_ |� �|j�|�|jt|<dS)NcSs|�d�dS)N)r)�_r r r r � weakref_cb�sz;ThreadPoolExecutor._adjust_thread_count.<locals>.weakref_cbz%s_%d)�name�targetrT)r2r=r4r0r9r6ZThreadr$�weakref�refr:r;Zdaemon�start�addr)rrEZ num_threadsZ thread_namer r r r r@�s      z'ThreadPoolExecutor._adjust_thread_countc Csd|j�Td|_xFy|j��}Wntjk r6PYnX|dk r|j�t|j��qWWdQRXdS)NzBA thread initializer failed, the thread pool is not usable anymore) r7r5r2Z get_nowaitr1ZEmptyrrr%)rr#r r r r�sz&ThreadPoolExecutor._initializer_failedTc CsD|j�d|_|j�d�WdQRX|r@x|jD] }|��q0WdS)NT)r7rr2rr4r)r�waitr r r r �shutdown�s  zThreadPoolExecutor.shutdown)Nr(Nr )T)rrr� itertools�count�__next__r8rrCr�Executorr&r@rrMr r r r r'ls    r')r&� __author__�atexitZconcurrent.futuresrrNr1r6rHr+�WeakKeyDictionaryrrr �register�objectrr$ZBrokenExecutorr%rQr'r r r r �<module>s   $