U e5d@"ã@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)Ú_baseFcCsBdatt ¡ƒ}|D]\}}| d¡q|D]\}}| ¡q,dS©NT)Ú _shutdownÚlistÚ_threads_queuesÚitemsÚputÚjoin)rÚtÚq©r ú1/usr/lib64/python3.8/concurrent/futures/thread.pyÚ _python_exit!s     rc@seZdZdd„Zdd„ZdS)Ú _WorkItemcCs||_||_||_||_dS©N)ÚfutureÚfnÚargsÚkwargs)Úselfrrrrr r r Ú__init__.sz_WorkItem.__init__c Csf|j ¡sdSz|j|j|jŽ}Wn2tk rT}z|j |¡d}W5d}~XYnX|j |¡dSr)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 rRz ||ŽWn<tk rPtjjddd�|ƒ}|dk rJ| ¡YdSXzx|jdd�}|dk rŽ| ¡~|ƒ}|dk rŠ|j ¡~qT|ƒ}t s¦|dks¦|j rÄ|dk r´d|_ |  d¡WdS~qTWn$tk rîtjjddd�YnXdS)NzException in initializer:T)Úexc_info)ÚblockzException in worker) rrZLOGGERZcriticalÚ_initializer_failedÚgetrÚ_idle_semaphoreÚreleaserr)Zexecutor_referenceZ work_queueÚ initializerÚinitargsZexecutorÚ work_itemr r r Ú_workerBs8    r(c@seZdZdZdS)ÚBrokenThreadPoolzR Raised when a worker thread in a ThreadPoolExecutor failed initializing. N)rrrÚ__doc__r r r r r)msr)c@sfeZdZe ¡jZddd„Zdd„Ze j jj e_ e j jj e_ dd „Z d d „Zdd d„Ze j jj e_ dS)ÚThreadPoolExecutorNÚr cCs¢|dkrtdt ¡pddƒ}|dkr.tdƒ‚|dk rFt|ƒsFtdƒ‚||_t ¡|_ t   d¡|_ 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)ÚminÚosÚ cpu_countÚ ValueErrorÚcallableÚ TypeErrorÚ _max_workersÚqueueZ SimpleQueueÚ _work_queueÚ threadingZ Semaphorer#ÚsetÚ_threadsÚ_brokenrZLockÚ_shutdown_lockÚ_counterÚ_thread_name_prefixÚ _initializerÚ _initargs)rZ max_workersZthread_name_prefixr%r&r r r rxs$     ÿzThreadPoolExecutor.__init__c Osät|ƒdkr|^}}}nV|s&tdƒ‚nHd|krZ| d¡}|^}}ddl}|jdtdd�ntdt|ƒdƒ‚|j�f|jr†t|jƒ‚|j r”t d ƒ‚t r t d ƒ‚t   ¡}t ||||ƒ}|j |¡| ¡|W5QR£SQRXdS) NézDdescriptor 'submit' of 'ThreadPoolExecutor' object needs an argumentrrz.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Ú RuntimeErrorrZFuturerr8rÚ_adjust_thread_count)rrrrrFÚfÚwr r r Úsubmitžs6    ÿ ÿ  zThreadPoolExecutor.submitcCs”|jjdd�rdS|jfdd„}t|jƒ}||jkr�d|jp>||f}tj|t t   ||¡|j|j |j fd�}d|_| ¡|j |¡|jt|<dS)Nr)ZtimeoutcSs| d¡dSr)r)Ú_r r r r Ú weakref_cbÈsz;ThreadPoolExecutor._adjust_thread_count..weakref_cbz%s_%d)ÚnameÚtargetrT)r#Úacquirer8rDr;r6r?r9ZThreadr(ÚweakrefÚrefr@rAZdaemonÚstartÚaddr)rrOZ num_threadsZ thread_namer r r r rJÁs&   ÿ ýÿ z'ThreadPoolExecutor._adjust_thread_countc Csb|j�Rd|_z|j ¡}Wntjk r6YqTYnX|dk r|j t|jƒ¡qW5QRXdS)NzBA thread initializer failed, the thread pool is not usable anymore) r=r<r8Z get_nowaitr7ZEmptyrrr))rr'r r r r!Ùs z&ThreadPoolExecutor._initializer_failedTc Cs@|j�d|_|j d¡W5QRX|r<|jD] }| ¡q.dSr)r=rr8rr;r )rÚwaitr r r r Úshutdownæs  zThreadPoolExecutor.shutdown)Nr,Nr )T)rrrÚ itertoolsÚcountÚ__next__r>rrMrÚExecutorÚ__text_signature__r*rJr!rXr r r r r+ss ÿ &   r+)r*Ú __author__ÚatexitZconcurrent.futuresrrYr7r9rSr1ÚWeakKeyDictionaryrrrÚregisterÚobjectrr(ZBrokenExecutorr)r\r+r r r r Ús   +