a XC?hC"ã@sÊdZdZddlmZddlZddlZddlZddlZddlZddl Z e  ¡Z da e  ¡Zdd„Ze e¡ee dƒrŠe jejejejd Gd d „d eƒZd d „ZGdd„dejƒZGdd„dejƒZdS)zImplements ThreadPoolExecutor.z"Brian Quinlan (brian@sweetapp.com)é)Ú_baseNFcCsftdaWdƒn1s0Ytt ¡ƒ}|D]\}}| d¡q8|D]\}}| ¡qPdS©NT)Ú_global_shutdown_lockÚ _shutdownÚlistÚ_threads_queuesÚitemsÚputÚjoin)rÚtÚq©r ú>/opt/alt/python39/lib64/python3.9/concurrent/futures/thread.pyÚ _python_exits"    rÚregister_at_fork)ZbeforeZafter_in_childZafter_in_parentc@s&eZdZdd„Zdd„ZeejƒZdS)Ú _WorkItemcCs||_||_||_||_dS©N)ÚfutureÚfnÚargsÚkwargs)Úselfrrrrr r rÚ__init__/sz_WorkItem.__init__c Csl|j ¡sdSz|j|ji|j¤Ž}Wn4tyZ}z|j |¡d}WYd}~nd}~00|j |¡dSr)rZset_running_or_notify_cancelrrrÚ BaseExceptionÚ set_exceptionZ set_result)rÚresultÚexcr r rÚrun5s  z _WorkItem.runN) Ú__name__Ú __module__Ú __qualname__rrÚ classmethodÚtypesÚ GenericAliasÚ__class_getitem__r r r rr.s rcCsð|durPz ||ŽWn:tyNtjjddd|ƒ}|durH| ¡YdS0zx|jdd}|durŒ| ¡~|ƒ}|durˆ|j ¡~qR|ƒ}t s¤|dus¤|j rÂ|dur²d|_ |  d¡WdS~qRWn"tyêtjjdddYn0dS)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Ú_workerEs8      r.c@seZdZdZdS)ÚBrokenThreadPoolzR Raised when a worker thread in a ThreadPoolExecutor failed initializing. N)rrr Ú__doc__r r r rr/psr/c@s`eZdZe ¡jZddd„Zdd„Ze j jj e_ dd „Z d d „Z dd dœdd„Ze j jj e_ dS)ÚThreadPoolExecutorNÚr cCs¢|durtdt ¡pddƒ}|dkr.tdƒ‚|durFt|ƒ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Ú_brokenrÚLockÚ_shutdown_lockÚ_counterÚ_thread_name_prefixÚ _initializerÚ _initargs)rZ max_workersZthread_name_prefixr+r,r r rr{s$     ÿzThreadPoolExecutor.__init__c Os´|jštv|jrt|jƒ‚|jr,tdƒ‚tr8tdƒ‚t ¡}t||||ƒ}|j   |¡|  ¡|WdƒWdƒS1sˆ0YWdƒn1s¦0YdS)Nz*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdown) rDrrBr/rÚ RuntimeErrorrZFuturerr>r Ú_adjust_thread_count)rrrrÚfÚwr r rÚsubmit¡s  zThreadPoolExecutor.submitcCsŽ|jjddrdS|jfdd„}t|jƒ}||jkrŠd|jp>||f}tj|t t   ||¡|j|j |j fd}| ¡|j |¡|jt|<dS)Nr)ZtimeoutcSs| d¡dSr)r )Ú_r r r rÚ weakref_cb»sz;ThreadPoolExecutor._adjust_thread_count..weakref_cbz%s_%d)ÚnameÚtargetr)r)Úacquirer>ÚlenrAr<rFr?ZThreadr.ÚweakrefÚrefrGrHÚstartÚaddr)rrOZ num_threadsZ thread_namer r r rrJ´s$   ÿ ýÿ z'ThreadPoolExecutor._adjust_thread_countc Cst|jZd|_z|j ¡}Wntjy4YqRYn0|dur|j t|jƒ¡qWdƒn1sf0YdS)NzBA thread initializer failed, the thread pool is not usable anymore) rDrBr>Ú get_nowaitr=ÚEmptyrrr/)rr-r r rr'Ës z&ThreadPoolExecutor._initializer_failedTF)Úcancel_futuresc Cs”|jbd|_|rNz|j ¡}Wntjy8YqNYn0|dur|j ¡q|j d¡Wdƒn1sn0Y|r|j D] }|  ¡q‚dSr) rDrr>rXr=rYrZcancelr rAr )rÚwaitrZr-r r r rÚshutdownØs  * zThreadPoolExecutor.shutdown)Nr2Nr )T)rrr Ú itertoolsÚcountÚ__next__rErrMrÚExecutorr0rJr'r\r r r rr1vs ÿ &  r1)r0Ú __author__Zconcurrent.futuresrr]r=r?r"rTr7ÚWeakKeyDictionaryrrrCrrZ_register_atexitÚhasattrrrRÚ_at_fork_reinitr*Úobjectrr.ZBrokenExecutorr/r`r1r r r rÚs,   þ+