o ?OgC"@sdZdZddlmZddlZddlZddlZddlZddlZddl Z e Z da e ZddZeeee drEe jejejejd Gd d d eZd d ZGdddejZGdddejZdS)zImplements ThreadPoolExecutor.z"Brian Quinlan (brian@sweetapp.com))_baseNFcCsft daWdn1swYtt}|D] \}}|dq|D]\}}|q(dSNT)_global_shutdown_lock _shutdownlist_threads_queuesitemsputjoin)rtqr @/opt/alt/python310/lib64/python3.10/concurrent/futures/thread.py _python_exits     rregister_at_fork)ZbeforeZafter_in_childZafter_in_parentc@s&eZdZddZddZeejZdS) _WorkItemcCs||_||_||_||_dSN)futurefnargskwargs)selfrrrrr r r__init__/s z_WorkItem.__init__c Csn|jsdSz |j|ji|j}Wnty.}z|j|d}WYd}~dSd}~ww|j|dSr)rZset_running_or_notify_cancelrrr BaseException set_exceptionZ set_result)rresultexcr r rrun5s  z _WorkItem.runN) __name__ __module__ __qualname__rr classmethodtypes GenericAlias__class_getitem__r r r rr.s rcCs|dur(z||Wnty'tjjddd|}|dur$|YdSwz; |jdd}|durG|~|}|durE|j~q)|}t sS|dusS|j rb|durZd|_ | dWdS~q*tyutjjdddYdSw)NzException in initializer:T)exc_info)blockzException in worker) rrZLOGGERZcritical_initializer_failedgetr_idle_semaphorereleaserr )Zexecutor_referenceZ work_queue initializerinitargsZexecutor work_itemr r r_workerEs@      r.c@seZdZdZdS)BrokenThreadPoolzR Raised when a worker thread in a ThreadPoolExecutor failed initializing. N)rrr __doc__r r r rr/psr/c@sdeZdZejZ  dddZddZe j jj e_ dd Z d d Z dd dddZe j jj e_ dS)ThreadPoolExecutorNr cCs|durtdtp dd}|dkrtd|dur#t|s#td||_t|_ t d|_ t |_d|_d|_t |_|pGd ||_||_||_dS) aInitializes 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)minos cpu_count ValueErrorcallable TypeError _max_workersqueueZ SimpleQueue _work_queue threadingZ Semaphorer)set_threads_brokenrLock_shutdown_lock_counter_thread_name_prefix _initializer _initargs)rZ max_workersZthread_name_prefixr+r,r r rr{s$      zThreadPoolExecutor.__init__c Os|jNt;|jrt|j|jrtdtrtdt}t||||}|j || |WdWdS1sDwYWddS1sTwYdS)Nz*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdown) rDrrBr/r RuntimeErrorrZFuturerr>r _adjust_thread_count)rrrrfwr r rsubmits  RzThreadPoolExecutor.submitcCs|jjddr dS|jfdd}t|j}||jkrGd|jp||f}tj|t t |||j|j |j fd}||j||jt|<dSdS)Nr)ZtimeoutcSs|ddSr)r )_r r r r weakref_cbsz;ThreadPoolExecutor._adjust_thread_count..weakref_cbz%s_%d)nametargetr)r)acquirer>lenrAr<rFr?ZThreadr.weakrefrefrGrHstartaddr)rrOZ num_threadsZ thread_namer r r rrJs&     z'ThreadPoolExecutor._adjust_thread_countc Cst|j-d|_ z|j}Wn tjyYnw|dur'|jt|jqWddS1s3wYdS)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|j0d|_|r& z|j}Wn tjyYn w|dur%|jq |jdWdn1s6wY|rG|j D]}| q@dSdSr) rDrr>rXr=rYrZcancelr rAr )rwaitrZr-r r r rshutdowns&    zThreadPoolExecutor.shutdown)Nr2Nr )T)rrr itertoolscount__next__rErrMrExecutorr0rJr'r\r r r rr1vs  &  r1)r0 __author__Zconcurrent.futuresrr]r=r?r"rTr7WeakKeyDictionaryrrrCrrZ_register_atexithasattrrrR_at_fork_reinitr*objectrr.ZBrokenExecutorr/r`r1r r r rs.   +