B *>ƒbÉàÝã@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ÔtjjdddYnXdS)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ƒ‚|jZ|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..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|jTd|_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|jd|_|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 Ús   $